Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-20 05:26:55


On Mon, Oct 20, 2003 at 06:03:35AM -0400, David Abrahams wrote:
> OK, next you write:
>
> instance Monad [] where
> bind m k = concat (map m k)
> unit x = [x]
>
> Does this "m" refer back to the "m" in
>
> class Monad m where
> ...
>
> ??

No. "m" and "k" are just the conventional names for bind's arguments
(I have no clue why). Rename them "arg1" and "arg2" if you like.

> It does. The use of "bind" is still beyond me, but I'll read on...

It possibly will be helpful to know that, e.g., eventually the list
comprehension

   [ x+y | x <- [1,2,3], y <- [0,10] ] -- yields [1,11,2,12,3,13]

is just syntactic sugar for

   [1,2,3] `bind` \x ->
      [0,10] `bind` \y ->
         unit (x+y)

But probably not. In my experience, you have to do a few passes on
monads before it becomes clear how the basic monad stuff is motivated by
the final results of using monads.

-- 
-Brian McNamara (lorgon_at_[hidden])

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk