[Haskell-cafe] Re: map (-2) [1..5]
lemming at henning-thielemann.de
Mon Sep 11 10:59:50 EDT 2006
On Sun, 10 Sep 2006, Aaron Denney wrote:
> >> 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", (*), ...?
from http://darcs.haskell.org/numericprelude/src/Algebra/Core.lhs :
> class (Num a) => Integral a where
> div, mod :: a -> a -> a
> divMod :: a -> a -> (a,a)
> -- Minimal definition: divMod or (div and mod)
> div a b = fst (divMod a b)
> mod a b = snd (divMod a b)
> divMod a b = (div a b, mod a b)
More information about the Haskell-Cafe