
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"

On 28 August 2010 10:38, michael rice
fmap seems oddly named because no "mapping" takes place, except in the fourth example, where the map is "passed in." Just sayin'.
*ahem* http://en.wikipedia.org/wiki/Map_%28mathematics%29
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
Right; this is because the fmap only gets the "Char -> Char" function inside the IO; but since it's "IO String" rather than "IO Char", this doesn't type-check. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

A "map" can be a function (applied to a (single) value).
Got it.
Thanks,
Michael
--- On Fri, 8/27/10, Ivan Lazar Miljenovic
fmap seems oddly named because no "mapping" takes place, except in the fourth example, where the map is "passed in." Just sayin'.
*ahem* http://en.wikipedia.org/wiki/Map_%28mathematics%29
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
Right; this is because the fmap only gets the "Char -> Char" function inside the IO; but since it's "IO String" rather than "IO Char", this doesn't type-check. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com
participants (2)
-
Ivan Lazar Miljenovic
-
michael rice