
On 4 May 2007, at 08:43, Adrian Neumann wrote:
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.
I suggest you look up currying. In the mean time, I shall attempt an explanation. In Haskell (as in many other functional languages), function types appear as if the function were curried. This means that a function accepts one single argument, and returns one single result. The important thing to realise though is that the result (or less importantly the argument) may be a function. Let's study a (slightly over constrained) variant on the (+) function, with type (+) :: Int -> Int -> Int. This type signature should be read to mean: (+) takes an Int, and returns a new function of type (Int -> Int). We can see an example of this (+ 5) -- (+) is given an argument (5), and returns a function (that adds 5 to integers). Another way to think about it is that the (->) type constructor is right associative, so any type written as a -> b -> c -> d -> e, can also be written as a -> (b -> (c -> (d -> e))). I hope that helped a bit, and if it didn't I suggest going and looking up currying in as many places as you can. Bob