[Haskell-cafe] map (-2) [1..5]
brianh at metamilk.com
Thu Aug 17 21:49:45 EDT 2006
Jared Updike wrote:
>> 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 that the
> way to type in
> 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.
>  http://wadler.blogspot.com/2006/01/bikeshed-coloring.html
This choice of precedence for unary - conflicts with the normal usage in
languages like C, where unary ops "obviously" bind tighter than infix.
The typesetting in maths conveys a lot of info eg to distinguish f -x from
f - x or f-x, and so the relationship between the visual representation and
the meaning depends on a knowledge of various conventions that have evolved
over time, and the knowledge of when to apply them in a given context.
In contrast, a programming language should be based on general concepts
uniformly applied. In Haskell we have operators, identifiers, prefix
application using an identifier and infix application using a symbol, and a
uniform way to convert a symbol to an identifier and vice versa, and a
uniform way of forming sections.
All this machinery should be enough to be satisfied with. However, someone
somewhere decided that one trivial arithmetic operation, namely unary minus,
should be allowed to totally ruin everything, and not only that, but that
half of any number line, the positives, should (literally!) have a special
advantage over the other half, the negatives.
Thus while I can agree with Wadler that it's easy to have different opinions
on "little" issues, I think that in this case the goal of uniformity leads
to an objective answer.
Of course not all languages care about being uniform or neat ;-)
Best 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.
More information about the Haskell-Cafe