Folks,
Here is my decision about `div` and friends: I've decided to back off
from the proposal to incorporate Common Lisp's capabilities, since it's
probably just too much stuff to consider in such a short timeframe.
(I also suspect that the Scheme designers correctly decided that the
CL stuff was overblown.) I considered making no changes at all, that
is to say, sticking with Scheme's collection of functions, but it really
is odd that they provide a pair of division/remainder functions and
another remainder function without its corresponding division, so
we will just minimally complete the picture with the missing functions.
I think that Kent's suggestion to rename the truncating division `quo`,
after Scheme's "quotient" and use `div` for flooring division as in
SML has merit, but I hesitate to introduce a potentially dangerous
incompatible change at this point.
At any rate, here's the new Integral class declaration:
class (Real a) => Integral a where
div, rem, dvf, mod :: a -> a -> a
divRem, dvfMod :: a -> a -> (a,a)
even, odd :: a -> Bool
toInteger :: a -> Integer
n `div` d = q where (q,r) = divRem n d
n `rem` d = r where (q,r) = divRem n d
n `dvf` d = q where (q,r) = dvfMod n d
n `mod` d = r where (q,r) = dvfMod n d
dvfMod n d = if signum r == - signum d then (q-1, r+d) else qr
where qr@(q,r) = divRem n d
even n = n `rem` 2 == 0
odd = not . even
Cheers,
--Joe