April 05, 2008
Janice Caron wrote:
> Exactly how could the compiler deduce a version with const or mutable
> arguments? Would it be (a)
> 
>     invariant(C) f(const(C) x)
> 
> or would it be (b)
> 
>     const(C) f(const(C) x)
> 

You could use return const. But I'm not entirely sure. I was explaining what I understood of someone else's proposal.
April 05, 2008
Lars Noschinski wrote:
> * Jarrett Billingsley <kb3ctd2@yahoo.com> [08-04-05 05:15]:
>> I'm not one to be listened to, but I think the idea behind monads is to wrap an inherently impure action (like IO) in a functional shell.  In an imperative language, you do something like:
> 
> Monads are an imperative sublanguage. IO Monads (which are the ones able
> to do impure things) are safe, because there is no way to extract the
> information wrapped in the monad.
> 
> So if you do a read, you don't get a "String", you get an "IO String"
> (i.e. an IO monad containing a string). But you can apply functions to
> the IO monad, which operate on the wrapped value and return a new IO
> monad (for example a method parsing the String to an integer).
> 
> For the functional part of the program (all things outside of the IO
> monad), the return value of e.g. readLine is always the same - an IO
> monad representing the action of reading a line of input and therefore
> it is pure.

Hmm, so would it be correct to say that monad is just another way to say 'impure function'?  It sounds like that's all you're saying.  So just like we're going to have 'pure' to isolate the functional code in D, functional languages have 'impure' functions that isolate the procedural/stateful stuff.  They just happen to give those impure functions a ridiculous name.

Seriously why on earth are they called 'monads'?  Sounds like it derives from "mono" meaning "one", like "triad" is a group of three things.  So 'monad' should mean a group of one thing I would thing.  Yet it means "impure function".  Really odd.  I hate it when people give things terrible non-descriptive names.  But maybe there's a rational explanantion?

--bb
April 05, 2008
Bill Baxter wrote:

> Lars Noschinski wrote:
>> * Jarrett Billingsley <kb3ctd2@yahoo.com> [08-04-05 05:15]:
>>> I'm not one to be listened to, but I think the idea behind monads is to wrap an inherently impure action (like IO) in a functional shell. In an imperative language, you do something like:
>> 
>> Monads are an imperative sublanguage. IO Monads (which are the ones able to do impure things) are safe, because there is no way to extract the information wrapped in the monad.
>> 
>> So if you do a read, you don't get a "String", you get an "IO String" (i.e. an IO monad containing a string). But you can apply functions to the IO monad, which operate on the wrapped value and return a new IO monad (for example a method parsing the String to an integer).
>> 
>> For the functional part of the program (all things outside of the IO monad), the return value of e.g. readLine is always the same - an IO monad representing the action of reading a line of input and therefore it is pure.
> 
> Hmm, so would it be correct to say that monad is just another way to say 'impure function'?  It sounds like that's all you're saying.  So just like we're going to have 'pure' to isolate the functional code in D, functional languages have 'impure' functions that isolate the procedural/stateful stuff.  They just happen to give those impure functions a ridiculous name.
> 
> Seriously why on earth are they called 'monads'?  Sounds like it derives from "mono" meaning "one", like "triad" is a group of three things.  So 'monad' should mean a group of one thing I would thing.  Yet it means "impure function".  Really odd.  I hate it when people give things terrible non-descriptive names.  But maybe there's a rational explanantion?

I always thought it had to do with money, but then I'm not a native English speaker ...

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango
April 06, 2008
On Sat, 05 Apr 2008 15:43:16 +0000, Sean Kelly wrote:

> == Quote from Christopher Wright (dhasenan@gmail.com)'s article
>> Agreed. People are mixing languages a decent amount these days; I'd like to see an official, supported way to integrate, say, Erlang with D, so that I can have Erlang parallelize stuff and D do the actual work.
> 
> Same here.  I have no interest in "one language to rule them all."  I prefer a specialized tool for the task at hand.
> 
> 
> Sean

Well, I'm surprised to be getting people agreeing, I kind of expected to
be the black sheep here.
I was kind of serious about the functional dialect of D though. It seems
Walter is keenly interested in exploring functional techniques, so this
might be a better way to get them implemented. No need to hack up D and
make it too complicated.
April 06, 2008
Bill Baxter wrote:
> 
> Seriously why on earth are they called 'monads'?

http://en.wikipedia.org/wiki/Monads_in_functional_programming

"The name monad derives from category theory, a branch of mathematics that describes patterns applicable to many mathematical fields. (As a minor terminological mismatch, the term "monad" in functional programming contexts is usually used with a meaning corresponding to that of the term "strong monad" in category theory, a specific kind of category theoretical monad.[citation needed])"

-Jeff
April 06, 2008
Jeff Nowakowski wrote:
> Bill Baxter wrote:
>>
>> Seriously why on earth are they called 'monads'?
> 
> http://en.wikipedia.org/wiki/Monads_in_functional_programming
> 
> "The name monad derives from category theory, a branch of mathematics that describes patterns applicable to many mathematical fields. (As a minor terminological mismatch, the term "monad" in functional programming contexts is usually used with a meaning corresponding to that of the term "strong monad" in category theory, a specific kind of category theoretical monad.[citation needed])"

Hmm, comes close, but doesn't really explain it.  So the reason they are called monads is because they are like "strong monads" from category theory.  So why are they called "strong monads" in category theory?

Anyway, thanks for trying to help despite my laziness.  :-)

--bb
April 07, 2008
"Walter Bright" wrote
> Andrei Alexandrescu's talk just given at ACCU:
>
> http://www.digitalmars.com/d/2.0/accu-functional.pdf

Thanks for posting this.  I think this is the first time you have laid out the plans/rules for pure functions in D, and it confirms what I already had inferred :)

-Steve


April 08, 2008
This reminds me 'The Power of None' presentation by Andrei Alexandrescu:

http://www.nwcpp.org/Meetings/2006/05.html
http://www.nwcpp.org/Downloads/2006/The_Power_of_None.ppt

On Sat, 05 Apr 2008 04:54:26 +0400, Simen Kjaeraas <simen.kjaras@gmail.com> wrote:

> On Sat, 05 Apr 2008 02:03:29 +0200, Bill Baxter <dnewsgroup@billbaxter.com> wrote:
>
>> Simen Kjaeraas wrote:
>>> On Sat, 05 Apr 2008 01:09:14 +0200, Jason House <jason.james.house@gmail.com> wrote:
>>>
>>>> bearophile wrote:
>>>>> P. 31: >writeln(i);<
>>>>>
>>>>> Can you put (temporary) debugging writeln/putr inside a pure function?
>>>>
>>>> That's always bothered me about this stuff.  I don't want to lose
>>>> debugging/logging ability!
>>>   Just use multiple return types, and have the caller do the printing.
>>>  --Simen
>>
>>
>> Monads!
>>
>> Or at least I think that's what I read somewhere.  I can't understand the buggers for the life of me.  I think maybe it's just a fancy word for "loophole".  If someone here has a good explanation for what a monad is and how it allows mutable state in FP without making thing non-FP, I'd love to hear it.  Because I just don't get it.
>>
>> --bb
>
> I read a bit on Wikipedia about monads, and they seem to me to be a fancy way to do multiple return values. I'm not sure if they're usable (hackable) in D at the moment, or if we need to wait for AST macros before we can use them as they should. But one example, the 'maybe' monad, seems to me a bit like this:
>
> struct Maybe(T)
> {
>    bool Nothing;
>    T data;
>
>    static Maybe!(U) opCall(U)(lazy U u)
>    {
>      typeof(return) tmp;
>
>      try
>      {
>        data = u();
>        tmp.Nothing = false;
>      }
>      catch (object o)
>      {
>        tmp.Nothing = true; // something went wrong, data is invalid
>      }
>    }
>
>    T opAdd(T rhs)
>    {
>      if (Nothing)
>        return rhs; // act as if data is nonexistant
>      else
>        return data + rhs;
>    }
>
>    // other operators overloaded in similar ways
> }
>
>
> Disclaimer: This might or might not work. It might contain some value of truth, and it might not. It is merely my understanding after a half-hour of reading at 2:30 in the morning, and so should be sanity-checked before use.
>
> -- Simen

April 08, 2008
On Tue, 08 Apr 2008 14:16:06 +0200, Koroskin Denis <2korden+dmd@gmail.com> wrote:

> This reminds me 'The Power of None' presentation by Andrei Alexandrescu:
>
> http://www.nwcpp.org/Meetings/2006/05.html
> http://www.nwcpp.org/Downloads/2006/The_Power_of_None.ppt
>

Thanks, I hadn't read that.

-- Simen
1 2 3 4
Next ›   Last »