Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-20 09:25:53


Brian McNamara <lorgon_at_[hidden]> writes:

> 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.

I see that happening, and it makes sense... but it's not at all clear
to me that the Haskell designers have ahold of something fundamental
and important in that bind signature. It seems somewhat arbitrary.

> 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.

I guess I'm wondering how much of the basic monad stuff is motivated
by the final results in the specific case of the list monad. The
signature of the "k" function (a -> m b) seems particularly
suspicious to me.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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