The -> in type signatures associates to the right, so the type signatures

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

are the same as:

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

Sometimes people put in the extra parentheses because they want to emphasize a particular way to use the function.

I'm assuming you understand that a function that takes two arguments and returns a (possibly non-function) value is equivalent to a function that takes one argument that returns a function that takes the other argument and returns a value.

HTH,

Mike



Adrian Neumann wrote:
-----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-----
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to