map and fmap

Iavor Diatchki iavor.diatchki at gmail.com
Thu Aug 17 14:41:37 EDT 2006


Hello,

On 8/15/06, John Hughes <rjmh at cs.chalmers.se> wrote:
> ... However, this isn't a complete solution, because students still see plenty of class constraints in error messages, and they need to understand them sufficiently well to fix their errors. It's not too hard to explain that "Num a" means that a should be a numeric type--Integer, Double, i.e. a type they are familiar with. It's much harder to explain what "Functor f" means to a student who's still struggling to keep in mind the difference not just between a type and a class, but between a type and a value. The fact that f is a type constructor, and not a familiar type, is an additional obstacle. That makes overloading list operations much more of an obstacle for beginners, than overloading numeric operations is.

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.

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.  Students can then simply
add it to the beginning of their programs, or (if they know about
modules) create their own module, or they could import it from a
predefined  'StudentPrelude'.  (As someone else pointed out, this is
not at all specific to Haskell: I've taken---and helped
design---classes for Java and C++ which did exactly this.)  When later
in the class students learn about overloading, then the lecturer could
tell them that the standard library already provides an overloaded
'map' function, that can be used for many different types, and they
can start using it.

Out of curiosity, how do people explain why 'map' is called that?

-Iavor


More information about the Haskell-prime mailing list