I'd like to ask some questions about the structure of the Num class, in 
particular why aren't the intrinsic sub-classes of Ring and Field separated 
out from the definition of Num and Fractional?

Why not have something like the following?
\begin{code}
class Ring a where
     (+), (-), (*)       :: a -> a -> a
     negate              :: a -> a
     fromInteger         :: Integer -> a
class  (Eq a, Show a, Eval a, Ring a) => Num a where
     abs, signum         :: a -> a
class Ring a => Field a where
     (/)                 :: a -> a -> a
     recip               :: a -> a
     fromRational        :: Rational -> a
class (Num a, Field a) => Fractional a where
     { }
\end{code}

Doing this would allow implementations of other Ring types such as 
Polynomials and Matrices to fit more comfortably into the existing prelude 
class framework.  I've tried this on the HUGS prelude and it seems to work 
ok.

Now I can see one snag, which is that existing instance definitions would be 
broken - but is there a good reason not to allow an instance declaration for 
one class to simultaneously declare instances for parent classes?  Doing 
this would allow the detailed parent class structure to be changed without 
affecting instance declarations.

Please let me know if this makes sense.  Is there a compelling reason why 
these two things are not done in the current system?


Reply via email to