I have been studying Haskell for several weeks now (just for fun) and just watched Brian Beckman's great video introducing monads. He motivates monads with the need to create a more general composition operator. Following this line of thought, if I have two functions:
f :: a -> b
g :: b -> c
the composition operator should satisfy
h = g . f :: a -> c
and from this I can infer the correct type of the .
operator:
(.) : (b -> c) -> (a -> b) -> (a -> c)
When it comes to monads, suppose I have two functions:
f :: a -> m b
g :: b -> m c
It seems to me that the natural choice would have been to define a generalized composition operator that works as follows:
h = f >>= g :: a -> m c
in which case the >>=
operator would have a type signature of:
(>>=) :: (a -> m b) -> (b -> m c) -> (a -> m c)
But actually the operator seems to be defined so that
h a = (f a) >>= g :: m c
and thus
(>>=) : m b -> (b -> m c) -> m c
Could someone explain the reasoning behind this choice of definition for bind? I assume there is some simple connection between the two choices where one can be expressed in terms of the other, but I'm not seeing it at the moment.