How does return> => f work in Haskell?
Specifically, my question is, how is this considered to be equivalent to f itself?
We know that the type return
is :: a -> m a
and the type >=>
is :: (a -> m b) -> (b -> m c) -> (a -> m c)
So, when we apply >=>
to return
and f, there will be no type since we will not have (a -> m a) -> (b -> m c)
both types return
and f respectively, which means how can we now apply >=>
now?
source to share
Let's rename some type variables to avoid confusion:
return :: a -> m a
(>=>) :: (b -> m c) -> (c -> m d) -> (b -> m d)
When we apply (>=>) return
, we need to do
(a -> m a) = (b -> m c)
(type return
and type of the first argument >=>
).
Therefore, we have
a = b
a = c
(and therefore b = c
also).
Then
(>=>) return :: (c -> m d) -> (b -> m d)
a = b
a = c
which the
(>=>) return :: (a -> m d) -> (a -> m d)
Until then f :: a -> m d
, we can apply (>=>) return
to f
and return a value of the same type.
source to share