Re: A propos de monad/About monads

From: David Brown (
Date: Sat Oct 02 1999 - 20:10:06 MET DST

Date: Sat, 2 Oct 1999 11:10:06 -0700 (PDT)
To: "CAML Mailing list" <>
Subject: Re: A propos de monad/About monads
In-Reply-To: <>
From: David Brown <>

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

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:25 MET