[Haskell-cafe] map (-2) [1..5]
Jared Updike
jupdike at gmail.com
Thu Aug 17 19:40:18 EDT 2006
> Yes but my point is that -4^2 is not the same as
>
> 2
> -4
>
> because the latter by convention means - (4^2).
> In other words, superscripts bind tighter than prefix ops but prefix ops
> bind tighter than infix.
I see. My point is that there already exists a convention[1] that the
way to type in
2
-4
is -4^2 which means -(4^2) not (-4)^2 because - as a prefix op has the
same precedence as binary subtraction, not super tight like normal
prefix ops (i.e. normal function application) as you would like it to
be (if I understand correctly). You are welcome to break an existing
(unofficial) convention for the sake of lexical syntax[2].
Cheers,
Jared.
[1] On my TI89 calculator (where there are even two - buttons: a
little "negative unary" button and a "binary subtract" button). It
pretty prints
2
-4 = -16
when I punch in -4^2 (where - is the "negative unary" button). The
answer is -16. Python (-4**2 = -4 ** 2 = - 4 ** 2 = -16) and Matlab
and Mathematica agree (-4^2 = -4 ^ 2 = - 4 ^ 2 = -16).
[2] http://wadler.blogspot.com/2006/01/bikeshed-coloring.html
--
http://www.updike.org/~jared/
reverse ")-:"
More information about the Haskell-Cafe
mailing list