[Haskell-beginners] fmap Maybe

Alexey Shmalko rasen.dubi at gmail.com
Mon Apr 27 10:12:44 UTC 2015


Hi, Shishir,

It's because Haskell uses juxtaposition for argument passing. So the first
case

fmap (\x -> x) Just 2

is equal to

(fmap (\x -> x) Just) 2

While

fmap (\x -> x+2) $ Just 2

is

fmap (\x -> x + 2) (Just 2)

I believe you want the latter.

Basically, the first example works because ((->) r) is an instance of
Functor.

instance Functor ((->) r) where
    fmap = (.)

So basically first example is:
((\x -> x) . Just) 2

Now you should see why it behaves this way.

Have a nice day!
Alexey Shmalko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150427/7e78229b/attachment.html>


More information about the Beginners mailing list