[Haskell-beginners] understanding function signature alignement

simkestuff at gmail.com simkestuff at gmail.com
Thu Aug 9 08:32:57 UTC 2018


Hello,

I'm going through Haskellbook and while doing some exercises I'm stack with
trying to explain myself how types matches in this examples:

meh :: Monad m => [a] -> (a -> m b) -> m [b]
meh [] _      = pure []
meh (x:xs) f = (:) <$> f x <*> meh xs f


flipType :: (Monad m) => [m a] -> m [a]
flipType xs = meh xs id

What puzzles me is how id function which is of type (a->a) can fit here
where meh function is requesting function of type (a->m b)?

The function (a -> m b) is function that says give me anything and I will
give back anything wrapped up into some monad structure; id ( a -> a) on
other hand says give me anything and I will return it back to you. So, to
me, the first function is somehow more restricted than id function because
it puts limitation on what output of that function can be and I'm
struggling to understand how id function can fit here.

I hope someone can help me how to reason about these functions here?

thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20180809/c5f0b6a2/attachment.html>


More information about the Beginners mailing list