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

Aaron Denney wnoise at ofb.net
Mon Sep 11 12:28:01 EDT 2006


On 2006-09-11, Henning Thielemann <lemming at henning-thielemann.de> wrote:
>
> 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)

That particular division means that Naturals can't support div because
they're not a ring, which the (Num a) in that snippet above means for
this numeric hierarcy, right?  So this does drag in div, mod and (*),
which all seem mostly reasonable, but it also drags in (-) and "negate",
which you don't want for Naturals.

-- 
Aaron Denney
-><-



More information about the Haskell-Cafe mailing list