Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-20 05:03:35


Brian McNamara <lorgon_at_[hidden]> writes:

> On Fri, Oct 17, 2003 at 04:55:12PM -0400, David Abrahams wrote:
>> Brian McNamara <lorgon_at_[hidden]> writes:
>
> So, returning to the concrete example at hand:
>
> bind :: m a -> ( a -> m b ) -> m b
> unit :: a -> m a
>
> Here 'm' is a "type constructor" (a one-argument function from types to
> types), and thus "m a" is a normal datatype.
>
>
> It might be helpful to think of this
>
> bind :: m a -> ( a -> m b ) -> m b
>
> as being analogous to
>
> template <template <class> class M, class A, class B>
> M<B> bind( M<A>, fcpp::fun1< A, M<B> > );
>
> where M is realized as a template-template parameter. (The actual
> FC++ implementation is done in a completely different way; this example
> is just for purpose of exposition.)

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

??

If so, in what way? I'd have thought you'd write:

      bind [] k = concat (map [] k)

or something, instead.

> To make things even more concrete, knowing that the general monad
> signature for unit is
>
> unit :: a -> m a
>
> consider these actual examples of FC++ code:
>
> list_m::unit( 3 ) // a value whose type is list<int>
> maybe_m::unit( 3 ) // a value whose type is maybe<int>
>
> Thus, in the list monad (represented by class fcpp::list_m in FC++),
> "m==fcpp::list" whereas in the maybe monad (class fcpp::maybe_m),
> "m==fcpp::maybe".
>
>
> Hope that helps some; I feel like that was awfully long-winded.

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

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