Version française
Home     About     Download     Resources     Contact us    
Browse thread
A propos de monad
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Brown <caml-list@d...>
Subject: Re: A propos de monad/About monads
David Mentr'e writes:

 > Monads are a way to encapsulate side-effects in functionnal
 > languages. Does anyboody have a more detailed explaination about how
 > monads really work ? What is the difference between the usual let and
 > the monad binding ?

Monads are primarily to encourage a lasy language (such as haskell) to 
evaluate side-effecting operations in a specific order.

In caml,

   let a = foo x y z in
   let b = bar g h i in
   blort a b

foo will be called before bar, and both will be called before blort.
So, if there are side effects in foo, and bar, and blort, we know what 
order these will happen in.

In a lazy language, foo will not be evaluated until blort needs to use 
its first argument.  Things could happen in blort before that.
Consequentially, some mechanism is needed to ensure an order.  Instead 
of "hiding" side-effecting operations wherever convenient, they are
encapsulated into a monad.  Other messages have given good references
to explanations.

Basically, instead of a function performing an operation, it returns a 
function that will perform that operation.  Monads provide a
convenient way to sequence these.  Also, the main program will return
a monad.  It is up to the runtime to then perform this operation
(basically outside of the scope of the language).

Dave Brown