[Haskell-cafe] Re: map (-2) [1..5]
wnoise at ofb.net
Sat Sep 9 09:34:03 EDT 2006
On 2006-09-08, Brian Hulley <brianh at metamilk.com> wrote:
> Leaving aside the question of negative literals for the moment, what's so
> special about unary minus that it warrants a special syntax? For example in
> mathematics we have x! to represent (factorial x), which is also an
> important function, yet no-one is arguing that we should introduce a unary
> postfix operator to Haskell just to support it.
Well, it seems a shame that we don't have postfix operators already.
I guess that means I am arguing we should introduce a unary postfix
operator, and not even have sugar for factorial, as it conflicts with
We *almost* do:
Hugs.Base> let (!) 0 = 1; (!) x = x*((!) (x-1)) in (5 !)
Prelude> let (!) 0 = 1; (!) x = x*((!) (x-1)) in (5 !)
No instance for (Num (t -> t1))
arising from the literal `5' at <interactive>:1:41
Probable fix: add an instance declaration for (Num (t -> t1))
In the first argument of `(!)', namely `5'
In the definition of `it':
it = let
! 0 = ...
! x = ...
in (5 !)
And hugs doesn't work with out the parentheses in the expression.
We already have this great syntax, parsing semanticsi for precedence,
and so forth for declaring infix operators. Couldn't we add to that
slightly by declaring postfix operators as well? Actually, declaring a
unary operator infix yielding a postfix operator doesn't seem like too
much abuse. I could have sworn I'd seen ternary operators the same way,
> ((id) `either` (id) (Left 5))
doesn't appear to work.
Then there's also the infix data constructors for postfix...
Okay, that's complicated because of lack of precedence, but surely that
just means extra parentheses?
(I haven't thought this through to any great extent. How much would it
complicate parsing? Not much, I would assume, as this fails in ghc at
the type-checking stage.)
(Tounge only *half* in cheek.)
More information about the Haskell-Cafe