Suggestion regarding (.) and map

Cale Gibbard cgibbard at gmail.com
Wed Apr 23 17:55:44 EDT 2008


Hello,

In keeping with my small but seemingly extremely controversial
suggestions for changes to the Prelude, here's a suggestion which I
think is elegant and worth considering for the Haskell' Prelude:

Rename fmap to map (like it was in Haskell 1.4), and define (.) as a
synonym for it.

Additionally, add the instance:

instance Functor ((->) e) where
    map f g x = f (g x)

(and hopefully the corresponding Monad instance as well)

This has the beautiful effect of unifying the notation for two of the
most important things in functional programming: function composition
and functorial application, and will hopefully reduce the number of
extraneous functor application definitions in the Prelude and
libraries.

Note that the fusion law for functors:

map (f . g) x = map f (map g x)

When written in terms of (.) becomes:

(f . g) . x = f . (g . x)

which means that (.) will still be reliably associative, and that the
functor in question is always easily determined by the type of the
last thing in any chain of (.)'s.

This has a fair level of backwards compatibility obviously, as it's
strictly a generalisation on both fronts. I've been playing around
with it for a while, and like it quite a lot myself, though it would
be more convenient to really use if it was in the Prelude.

 - Cale


More information about the Haskell-prime mailing list