I am currently in need of a bit of brain training and I found this article on Haskell and Monads

All the other exercises I am fine with - except one.

Excercise 7 is really messing with my brain.

Randomised function bind

To make the problem even simpler to experiment, I replaced the StdGen type with a n unspecified type. So instead of...

bind :: (a -> StdGen -> (b,StdGen)) -> (StdGen -> (a,StdGen)) -> (StdGen -> (b,StdGen))

I used...

bind :: (a -> c -> (b,c)) -> (c -> (a,c)) -> (c -> (b,c))

and for the actual function impelemtation (just straight from the exercise)

bind f x seed = let (x',seed') = x seed in f x' seed'

and also 2 randomised functions to trial with:

rndf1 :: (Num a, Num b) => a -> b -> (a,b)
rndf1 a s = (a+1,s+1)

rndf2 :: (Num a, Num b) => a -> b -> (a,b)
rndf2 a s = (a+8,s+2)

So with this in a Haskell compiler (ghci), I get...

:t bind rndf2
bind rndf2 :: (Num a, Num c) => (c -> (a, c)) -> c -> (a, c)

This matches the bind curried with rndf2 as the first parameter.

But the thing I don't get and have not been getting for the past days!! is how...

:t bind rndf2 . rndf1

Suddenly gives

bind rndf2 . rndf1 :: (Num a, Num c) => a -> c -> (a, c)

the correct type that we are eventually heading for.

So any help with understanding why the bind function needs to work like this would be most useful.