Pure functions in D

renoX renosky at free.fr
Thu Oct 9 13:39:11 PDT 2008


bearophile a écrit :
> renoX:
>> Sorry, but this is still above my level of understanding, and I've
>> been programming for quite a long time (and have been curious of
>> many things in programming)..
> 
> Around the net there are many tutorials on them, this is very simple:
>  
> http://www.reddit.com/r/programming/comments/64th1/monads_in_python_in_production_code_you_can_and/c02u9mb

I've read it too, without success also.

> To understand them I think you can: - I think you have to "unlearn"
> some of the things you know; - read explanations about them - to
> install Haskell and start learning it, with time you will learn.

No, I'm not interested in Haskell, as long as I can't learn monads I'm 
not interested plus there's D, Scala, F#, Ruby, etc, already lots of 
interesting language to learn..

>> In general yes, in this case no: AFAIK, monads are only useful for
>>  "pure" functional language which D isn't and won't ever be.
> 
> If you say you don't undestand monads, how can you tell they can't be
> useful for the future D? As far as we today know, monads allow you to
> use pure functions in the most effective way. For example using
> monads is the best known way to solve the logging and the exception
> problems of pure fuctions.

First I'm not convinced that pure functions have an issue with 
exceptions, second if you can cast an output function as a pure function 
(lying to the compiler in some way) then the logging issue is solved: 
this is something that I can understand easily, no need for weird monads.

> So I think they can be useful for the
> future D too.
> 
> 
>> IMHO, functional programming has some good stuff which are easy to
>> use and understand that D should steal such as "pure functions" but
>> monads aren't such thing: they're very hard to understand, so their
>> correct usage isn't obvious and in an impure language I fail to see
>> their interest..
> 
> They aren't so hard to understand. In C++ there are several concepts
> that are as much or more difficult to understand.

C++ isn't simple I agree, but usually the things really hard to 
understand are weird corner case, that one can mostly ignore but monads 
are a fundamental concepts for Haskell (otherwise no IO).

renoX


> 
> Bye, bearophile



More information about the Digitalmars-d mailing list