map and fmap
jyasskin at google.com
Sun Aug 20 17:10:43 EDT 2006
On 8/20/06, John Hughes <rjmh at cs.chalmers.se> wrote:
> 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.
There's a proposal
mentions extending defaulting to other typeclasses. That seems to fix
this particular problem, but above you mentioned that this was "a
whole new can of worms." Could you elaborate or point me to a
discussion of the worms?
More information about the Haskell-prime