[Haskell-cafe] The Trivial Monad

Adrian Neumann aneumann at inf.fu-berlin.de
Fri May 4 03:43:35 EDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I've read this blogpost about the "trivial monad"
http://sigfpe.blogspot.com/2007/04/trivial-monad.html, because I still
don't understand what this monad thingy is all about.

The author defines three functions:

data W a = W a deriving Show

return :: a -> W a
return x = W x

fmap :: (a -> b) -> (W a -> W b)
fmap f (W x) = W (f x)

bind :: (a -> W b) -> (W a -> W b)
bind f (W x) = f x

and asks the reader to prove the tree monad laws for them. However I
don't understand the type signatures for bind and fmap. I'd say (and
ghci's type inference agrees) that bind and fmap have the type

bind:: (a->W b) -> W a -> W b
fmap:: (a->b) -> W a -> W b

They take a function f and something and return what f does to that. I
don't see why they should return a function.

This of course makes it hard for me to prove the monad laws. The first
however works nonetheless:

1) bind f (return a)= f a

=> bind f (return a)= bind f (W a) = f a

Can someone explain bind and fmap (and possible law 2 and 3)?

Thanks,

Adrian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGOuQS11V8mqIQMRsRCmngAJ9NwQMwXeS/PSM1NUsVA8gxPuA0KACfSLiA
ItqRZW5a4XyQ099bhMtSWmU=
=/8i/
-----END PGP SIGNATURE-----


More information about the Haskell-Cafe mailing list