[Haskell-cafe] map (-2) [1..5]

Brian Hulley brianh at metamilk.com
Thu Aug 17 15:14:51 EDT 2006


Jared Updike wrote:
> -4^2    is not the same whether parsed as
>
> (-4)^2  or  -(4^2)  (the correct version)
>
> Basically, before someone argues this with me,
>
> -4^2 should parse the same as
>
> - 4^2 which should be the same thing as
>
> 0 - 4^2

I'd argue that -4^2 should parse as (-4)^2 in the same way that:

    f x `op` y    ===  (f x) `op` y

I'd also argue that in maths the necessary brackets are implied by the 
superscripting syntax, and for programming, as long as the editor does basic 
highlighting of literals it would be very clear that -4 is a single lexeme.

Stefan Monnier wrote:
>> I'd have thought it would have been simpler to just make the rule
>> that -2 (no spaces between '-' and '2') would be a single lexeme,
>
> But then x-2 won't mean "subtract 2 from x" but "call x with arg -2".

Literal highlighting in the editor would make it clear that x-2 === x (-2).
I think a basic issue is that at the moment it is strange that non-negative 
numbers can be specified as literals but negative numbers can't - they can 
only get in through the "back door" of evaluation - which just doesn't seem 
right.

It's kind of like a Monty Python'esque sketch of a lecture theatre full of 
mathematicians where every attempt to mention a negative number is replaced 
by the word "apple"... ;-)

Regards, Brian.

-- 
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.

http://www.metamilk.com 



More information about the Haskell-Cafe mailing list