[Haskell-cafe] map (-2) [1..5]
Brian Hulley
brianh at metamilk.com
Thu Aug 17 18:42:29 EDT 2006
Jared Updike wrote:
>> I'd also argue that in maths the necessary brackets are implied by
>> the superscripting syntax
>
> ASCII text parsing issues aside, in math,
>
> 2
> -4 = ?
>
> (No you cannot ask if there is space between the 4 and the - symbol,
> or if I "meant" (-4)^2 or -(4^2), or if I wrote a negative sign or a
> subtract sign. I believe there is only one standard interpretation
> here.)
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.
>
>> they can only get in through the "back door" of evaluation
>> which just doesn't seem right.
>
> Constant folding can eliminate any runtime cost, so effectively 0 - 2
> ==> negative 2 at compile time. No problem.
An Int8 has the range -128 to +127 inclusive, so I'd have expected a problem
with the expression
negate (128 :: Int8)
However I see from
http://en.wikipedia.org/wiki/Two's_complement#The_weird_number that this
works because -128 === +128 ie
negate (128::Int8)
=== negate (-128) -- literal to typed value
=== (+128) -- negation
=== (-128) -- overflow ignored
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