So I found out that fmap
, a Functor
function can be expressed in terms of Monadic operator >>=
and return
function like this:
fmap' :: (Monad m) => (a -> b) -> m a -> m b
fmap' g x = x >>= (\y ->
return (g y))
So my first question is how can we implement return function based on fmap
?
Also if we can implement return function based on fmap
, can we reduce Haskell expressions in do blocks? Would that produce more elegant code?
For instance:
Just x -> do
y <- f x
return (a:y)