[Haskell-cafe] On to applicative

michael rice nowgate at yahoo.com
Fri Aug 27 20:38:50 EDT 2010


fmap seems oddly named because no "mapping" takes place, except in the fourth example, where the map is "passed in." Just sayin'.

Michael

1)
Prelude Control.Monad Control.Applicative> fmap (++ "abc") getLine
xyz
"xyzabc"

2)
Prelude Control.Monad Control.Applicative Data.Char Data.String> fmap (splitAt 3) getLine
qwertyuio
("qwe","rtyuio")

3)
Prelude Control.Monad Control.Applicative Data.Char> fmap toUpper getLine

<interactive>:1:13:
    Couldn't match expected type `Char' against inferred type `[Char]'
      Expected type: IO Char
      Inferred type: IO String
    In the second argument of `fmap', namely `getLine'
    In the expression: fmap toUpper getLine

4)
Prelude Control.Monad Control.Applicative Data.Char Data.String> fmap (map toUpper) getLine
qwertyuio
"QWERTYUIO"






      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100827/5be61a47/attachment.html


More information about the Haskell-Cafe mailing list