map and fmap
rjmh at cs.chalmers.se
Fri Aug 18 11:30:53 EDT 2006
> From: "Iavor Diatchki" <iavor.diatchki at gmail.com>
> I know this is not exactly accurate, but for beginners' purposes one
> could explain 'Functor' as a container type such as a list or a tree.
Only to students who already know what a (parameterised) list and tree ARE.
Introducing both those concepts, and generalising them first over arbitrary
element types, and then over the kind of container, is something that will
take some time. It's on the way to that point that one needs to be able to
talk about and use lists, without encountering Functor even in error
> In any case, if one wanted to avoid the issue, it seems entirely
> reasonable to define a function 'mapList' that has the list specific
> type. Most classes probably do this anyway.
That would be the alternative, but I doubt whether any classes do that right
now. What's the point, when map already does the job?
> From: Jon Fairbairn <jon.fairbairn at cl.cam.ac.uk>
> A reasonable choice (forestalling the objection that using
> List.map, listMap or mapList would be too distracting for
> students) would be
> lmap:: (t -> t') -> [t] -> [t']
> map:: Functor f => (t -> t') -> f t -> f t'
I'd prefer mapList to lmap, to be honest--at least the connection between
and the type is clear. But remember, this would at a stroke make Haskell'
incompatible with all existing Haskell textbooks. Even if publishers brought
out new editions, even if we told students to buy them, there are many, many
second hand books in circulation, and it would be years before one could
on students having Haskell' books. All that time, students would write map
instead of mapList because that's what the book says, and get stuck with
incomprehensible error messages. Is it really worth an incompatible change
in the library functions used by all beginners, just to rename fmap to map?
It seems to me that the gain from a change is very small, and the cost
More information about the Haskell-prime