
On 2006-09-09, Jón Fairbairn
Aaron Denney
writes: 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?
I'd like it if you would, but don't expect to convince you.
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.
For a Natural typeclass to be useful in keeping full-blown Integers away from functions like "take", it can't be above the ones Integer belongs to. Instead it has to "hang off the side" of the numeric hierarchy. You can split this into a "tagging" class on the side and what naturals and integer have in common. Or, of course, you could onry allow one implementation of naturals, and have the Natural typeclass not used to enforce these restriction, but just the data type itself.
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 difference ever a useful function? I guess I don't see it as terribly natural. Placing it in the hierarchy somewhere above the class with (-) also means we can't have a default definition in terms of (-).
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.
That could work. I still don't like having a plus without a minus.
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 Naturals.
True. It seems odd to have a multiplicative (pseudo) inverse, but not an additive, though. Breaking up the numeric hierarchy too finely seems like it would be a pain -- take it to the limit of a separate class per function. What else would you drag in with "div"? "mod", (*), ...? I was thinking of useful implementations solely in terms of the Peano-axiom interface, which only really needs to be there for a default implementation. -- Aaron Denney -><-