[Haskell-cafe] Natural Numbers: Best implementation?

Wolfgang Jeltsch g9ks157k at acme.softbase.org
Fri Mar 13 04:37:48 EDT 2009


Am Freitag, 13. März 2009 09:21 schrieb Roman Cheplyaka:
> * Alexander Dunlap <alexander.dunlap at gmail.com> [2009-03-12 20:01:57-0700]
>
> > Also, a lot of functions just take
> > Integers so it would be more of a pain to use.
>
> AFAIK there are very few fuctions that take Integers. Many functions
> take instances of Integral, but it's not a problem to make your own type
> such an instance.

I’d say that it is a problem. Class instances should satisfy certain laws. 
(Although these laws are often not stated explicitely, they are assumed to 
hold by users of the class and they should hold to make the instance 
sensible.) In the case of Num, I would expect num + negate num to equal num. 
This wouldn’t hold for a Natural instance of Num.

Best wishes,
Wolfgang


More information about the Haskell-Cafe mailing list