|Version 6 (modified by simonmar@…, 9 years ago) (diff)|
get rid of unary '-' operator
the unary '-' is a very odd case in the report and causes a lot of confusion.
to fix it we can
- make '-' part of the lexical syntax of numbers. so a '-' followed by digits is interpreted as a negative number
- get rid of all other special treatment of '-'
- people can use 'negate' if they want to negate non literals.
- the removal of n + k patterns will make this more attractive
- This does introduce a syntactic oddity, namely that -1 is different from - 1 though syntax highlighting editors could make this distinction obvious.
- It would no longer be possible to write x-1 to mean "x minus 1", instead it would mean "x applied to the literal -1", which is counter-intuitive. Also, x - 1 with spaces would have the "x minus 1" meaning.
- In Haskell 98, '-' is explicitly excluded from right sections, so:
Prelude> :t (- 1) (- 1) :: (Num a) => a Prelude> :t (1 -) (1 -) :: (Num a) => a -> a
If we removed special treatment of '-', then these become symmetrical again. However it seems unintuitive that (-x) is a right section of '-', but (-1) is the literal -1.