[Haskell-beginners] Re: map question
Deniz Dogan
deniz.a.m.dogan at gmail.com
Sat Oct 17 14:41:30 EDT 2009
2009/10/17 Will Ness <will_n48 at yahoo.com>:
> 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) ?
>
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
`This` syntax is used to make functions work infix, whereas operators
already are infix. For this reason, it wouldn't make much sense to use
`this` syntax (what's that called anyways?) on an operator.
`(-)` would in some sense be the same thing as just "-", since () is
used to make operators prefix and `` is used to make functions infix.
--
Deniz Dogan
More information about the Beginners
mailing list