haskell - Fmap and map, I can't see the difference -


i'm trying understand functors are, far can't. what's difference between these 2:

prelude> fmap (+1) [1..9] [2,3,4,5,6,7,8,9,10]  prelude> map (+1) [1..9] [2,3,4,5,6,7,8,9,10] 

for lists, there no difference, map fmap specialised lists.

fmap has more general type:

fmap :: functor f => (a -> b) -> f -> f b 

this means can used functor e.g.

fmap (+ 3) (just 4)          -- 7 fmap (+ 4) (+ 3) 1           -- 8. functions functors fmap = (.) fmap read getline :: io int  -- io functor 

while map has type

map :: (a -> b) -> [a] -> [b] 

if @ source, functor instance lists defines fmap map:

instance functor []     fmap = map 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -