Suggestion regarding (.) and map
cgibbard at gmail.com
Fri Apr 25 00:36:06 EDT 2008
2008/4/24 David Menendez <dave at zednenem.com>:
> On Thu, Apr 24, 2008 at 6:06 PM, Twan van Laarhoven <twanvl at gmail.com> wrote:
> > Cale Gibbard wrote:
> > > 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.
> > >
> > One thing I fear (though that fear may be irrational) is that you get code
> > that looks like "(.) . ((.) . (.) .)". To me, and I expect to many people,
> > map and composition are different things, and used in different ways. If
> > both are written as a dot it will take extra mental effort to decipher the
> > meaning of a program. The potential for writing code that resembles the
> > worst outputs of the @pl lambdabot plugin also becomes larger.
> I'd much rather keep composition and functor map separate. I'm still
> not entirely sure that generalizing (.) to other morphisms in the
> Category class is a good idea. Function composition gets used a *lot*,
> and I imagine we'd loose a lot of inlining if it became a class
It should specialise quite nicely. The only places I'd expect you'd
lose optimisation would be those which were truly polymorphic
applications, which you otherwise couldn't have written as (.) anyway.
Someone who knows more about how GHC works might want to comment
further, but a simple SPECIALISE pragma for it should do the trick.
More information about the Haskell-prime