[Haskell-cafe] Re: map (-2) [1..5]

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Fri Sep 8 06:58:14 EDT 2006

"Cale Gibbard" <cgibbard at gmail.com> writes:
> Another thing to note is that all the natural literals are not, as one
> might initially think, plain values, but actually represent the
> embedding of that natural number into the ring (instance of Num), by
> way of 0 and 1.

I wasn't sure where to add this, so here will have to do:

I think the present design is wrong because we don't have a
type for naturals.  So in my view, “-1” should be “negate
(fromNatural 1)” -- whatever names we use for those two
functions.  I can't remember right now why the early
versions of Haskell didn't have a Natural type, or what
makes it difficult to change to now (and I think this is
something we really should do), but even given that, I think
the present special casing of “-” is a reasonable

Given a built in Natural type, it makes no sense to have “-”
as part of the syntax for literals, since Natural literals
don't have it and there's no way to add more constructors
(ie negative literals) onto an existing type to get Integer,
but having a symbol for negate does it in a straightforward

* ** *

For my own taste, I would have “-” as a character that can
appear in identifiers and operators (but special in that if
it appears at the beginning it cannot be followed by
anything? Otherwise -1 would just be an identifier!) and

> - n = negate n
> a +- b = a + (- b)

but I think that most people would baulk at having to use
“+-” for infix minus. People would similarly baulk at the
opposite tack of making “-” solely infix and using something
else for negate (as in ML), although finding a different
token (such as “__”) for "don't care" and using “_” for
unary minus doesn't seem too bad to me.

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk

More information about the Haskell-Cafe mailing list