Re:Brilliance of Haskell's Maybe type and the Value of Stati...
by tkahn6 on Sunday July 25, 2010 @09:36PM
(#1546827)
Also
So
Am I correct in saying that `fmap` is a functor which lifts the first argument `f` into the monad and then applies it to the second argument?
[ Parent
| on HN ]
Re:Brilliance of Haskell's Maybe type and the Value of Stati...
by jewbacca on Sunday July 25, 2010 @10:51PM
(#1546970)
WARNING: This is the blind leading the blind. I was already well-upvoted for my previous post before realizing (thanks to you, tkahn) that my definition of bind was actually fmap (I think). Crying out for authority here; help us out HN.
---
You are not, strictly/pedantically speaking, because fmap is the single function that defines a Functor to begin with [1]:
class Functor f where
fmap :: (a -> b) -> f a -> f b
and Monads are a special case of Functors; so, as the defining relation of a Functor, it doesn't a priori have anything to do with Monads.You are right in seeing that fmap is lifting -- liftM, which is defined in terms of just bind and return for Monads, is (I believe... see warning above) identically fmap. fmap = map for Lists as seen as Functors, for example, which lifts a function (a -> b) to ([a] -> [b])... "into" the Functor/Monad, I suppose.
---
[1] http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4...
Re:Brilliance of Haskell's Maybe type and the Value of Stati...
by johnbender on Sunday July 25, 2010 @10:08PM
(#1546897)
All Monads are, in theory if not in practice, Functors (there happens to be an instance of Functor defined for Maybe). fmap is not a functor but an arrow, in this case a function, that lifts f into the context of the Functor.