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

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Sat Sep 9 10:53:54 EDT 2006

Aaron Denney <wnoise at ofb.net> writes:

> Jón Fairbairn <jon.fairbairn at cl.cam.ac.uk> wrote:
> > I think the present design is wrong because we don't have a
> > type for naturals.
> Meh.  Naturals are reasonably useful sometimes, but not often enough, in
> my opinion.  Any sort of numeric hierarchy designed to deal with them
> would be totally broken from my point of view -- if you don't at least
> have inverses, it's not a number,

Crikey. Would you really have me accept that the natural
numbers aren't numbers?

> just some sort of weird algebraic structure.  And if it's
> not in the numeric hierarchy, and so you can't do
> arithmetic syntactically nicely with it, what's the point?

Could you elaborate? I haven't thought it through, but I
can't see why splitting Num into something that puts Natural
"above" Integer would be particularly problematic. Natural
just has fewer operations than Integer. It doesn't have “-”,
but it does have “difference:: Natural -> Natural ->
Natural”, and so do the bigger types (“difference a b = abs
(a - b)”)

> Is it better to make (^^), (^), and "take" partial functions, or to make (-)
> and "negate" partial functions?

No :-). “-” and “negate” would belong to a class of which
Natural had no instances.  If you're the sort of person who
likes having partial functions like “head” sullying the
scene, you might find it convenient to have
“integralToNatural” that either returns the corresponding
Natural or throws an exception. Actually, if you are someone
like that, you probably want to give it a shorter name...

> Of course, there's always a typeclass, where we could add all sorts of
> other encodings of the Peano axioms, such as binary trees,, but I don't
> see that that buys us much if we don't also get access to operations
> beyond them, such as (an _efficient_) `div` for fastexp.

I don't see why Natural can't have an instance of whatever
class ends up owning “div”.  It's perfectly well behaved on

Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk
http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2006-09-07)

More information about the Haskell-Cafe mailing list