
On Fri, Feb 09, 2001 at 12:55:12PM -0800, William Lee Irwin III wrote:
class (Eq a, Show a) => Num a where (+), (-), (*) :: a -> a -> a negate :: a -> a abs, signum :: a -> a fromInteger :: Integer -> a fromInt :: Int -> a -- partain: Glasgow extension
... So we have two totally inappropriate operations (fromInteger and fromInt), ...
I beg to differ on this point. One could provide a default implementation for fromInt(eger) as follows, assuming a 'zero' and 'one', which do obviously fit (they are the additive and multiplicative units): fromInteger n | n < 0 = negate (fromInteger (-n)) fromInteger n = foldl (+) zero (repeat n one) (Of course, one could use the algorithm in integer exponentiation to make this efficient.) Best, Dylan Thurston