[Haskell-cafe] Teaching Monads

Dan Doel dan.doel at gmail.com
Sat Jun 7 09:49:45 EDT 2008


On Saturday 07 June 2008, Ronald Guida wrote:
> 3. These closures are extremely similar to the closures that arise
>    when desugaring let-syntax.
>
>  let x1 = f1 in            f1 -$ (\x1 ->      Where:
>    let x2 = f2 in          f2 -$ (\x2 ->      (-$) :: a -> (a -> b) -> b
>      let x3 = f3 in        f3 -$ (\x3 ->      x -$ f = f x
>        f x1 x2 x3          f x1 x2 x3)))

In fact, this is the identity monad (this is not valid Haskell, but we'll let 
that slide):

    type Id a = a

    instance Monad Id where
      return a = a
      a >>= f  = f a

    do x1 <- f1             f1 >>= \x1           (\x1 ->
       x2 <- f2             f2 >>= \x2            (\x2 ->
       x3 <- f3             f3 >>= \x3              (\x3 -> f x1 x2 x3) f3)
       return (f x1 x2 x3)  return (f x1 x2 x3)    f2) f1

Which is the same as the lets modulo let-polymorphism and recursive bindings.

(In Haskell, you need a newtype wrapper but it's otherwise the same.)

> OK, so before I attempt to write a monad tutorial based on "manual
> plumbing" and "monadic plumbing", I would like to know, does anyone
> else think this is a good idea?

I think the general consensus is "don't write yet more monad tutorials." If 
you think Wadler's original paper is good, then it doesn't hurt to recommend 
it (you could instead write a "don't be afraid of reading academic papers" 
tutorial :)).

But don't let me stop you, of course. :)

-- Dan


More information about the Haskell-Cafe mailing list