[Haskell-beginners] Re: map question

Brent Yorgey byorgey at seas.upenn.edu
Sat Oct 17 14:43:36 EDT 2009


On Sat, Oct 17, 2009 at 06:29:39PM +0000, Will Ness wrote:
> Brent Yorgey <byorgey <at> seas.upenn.edu> writes:
> 
> > 
> > By the way, the reason
> > 
> >   map (+1) [1,2,3,4]
> > 
> > works but
> > 
> >   map (-1) [1,2,3,4]
> > 
> > doesn't is because of an ugly corner of Haskell syntax: -1 here is
> > parsed as negative one, rather than an operator section with
> > subtraction.  The 'subtract' function is provided exactly for this
> > purpose, so that you can write
> > 
> >   map (subtract 1) [1,2,3,4]
> > 
> 
> Then why wouldn't (`-`1) parse at at all? And not even (`(-)`1) ?
> 
> I know this doesn't parse, my question is, why wouldn't it be made valid 
> syntax? It seems consistent. (`mod`2) parses, why not (`-`2) ?

`backticks` are only for making (prefix) functions into (infix)
operators.  - is already an infix operator, so putting it in backticks
would be redundant.  As for `(-)`, arbitrary expressions cannot go
inside backticks, and for good reason: what would `(2 `mod`)` parse
as?  

However, certainly different choices might have been possible.

-Brent


More information about the Beginners mailing list