www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Full closures for D

reply Bruce Adams <tortoise_74 yeah.who.co.uk> writes:
0ffh Wrote:

 Bruce Adams wrote:
 KlausO Wrote:
 Someone with more a functional programming background may be able to
 enlighten us but doesn't the existence of proper closures allow us to
 implement monads as a library now? Though I can't quite see in what
 situation we would want to use them.

Yup, IIRC the poor strictly functional guys needs them for I/O, but as we're imperative anyway I don't see any applications for monads either. Regards, Frank

Since they're on the language comparison feature chat it implies (to me at least) that there is some perceived benefit to the concept. Any poor strictly functional guys care to explain what it is?
Nov 05 2007
parent Nathan Reed <nathaniel.reed gmail.com> writes:
Bruce Adams wrote:
 Since they're on the language comparison feature chat it implies (to me at
least) that there is some perceived benefit to the concept.
 Any poor strictly functional guys care to explain what it is?
 

Here's a good introduction to monads in the context of Haskell: http://research.microsoft.com/%7Esimonpj/Papers/marktoberdorf/mark.pdf Basically, a monad is a type whose values represent actions. An action is something that, when done, has an effect on some global state and then possibly returns a value. There are operators that allow actions to be composed in various ways. So, in a pure functional programming language, you never actually *do* anything imperatively - you just construct a huge action, which contains everything your program should do, by gluing together lots of itty-bitty actions (and pure functions). The construction of this action is done purely-fuctionally. Then the runtime executes the action, but this occurs outside of the language proper, so it doesn't hurt your beautiful clean pure-functionality. Thanks, Nathan Reed
Nov 05 2007