map and fmap

John Hughes rjmh at cs.chalmers.se
Sun Aug 20 09:52:10 EDT 2006


From: "Jon Fairbairn" <jon.fairbairn at cl.cam.ac.uk>

> To
> reinforce what Aaron said, if a programme works now, it'll
> still work if map suddenly means fmap.

Well, this isn't quite true, is it? Here's an example:

class Foldable f where
  fold :: (a -> a -> a) -> a -> f a -> a

instance Foldable [] where
  fold = foldr

example = fold (+) 0 (map (+1) (return 2))

example has the value 3 (of course), but if you replace map by fmap then the 
code no longer compiles.

In any case, I'm dubious about this as a criterion. I would guess that the 
majority if compiler runs for beginners (and perhaps for the rest of us 
too!) end in a type error, not a successful compilation, so arguably the 
quality of error messages when a type-check fails is more important than 
which programs compile.

John





More information about the Haskell-prime mailing list