Lennart Augustsson wrote:
| class C a where
| m :: a -> Int
|
| class (C a) => C1 a where
| m x = 1
|
| class (C a) => C2 a where
| m x = 2
|
| class (C1 a, C2 a) => C12 a
|
| f :: (C12 a) => a -> Int
| f x = m x
|
| Will f return 1 or 2?
Maybe we should do it as follows:
At the moment you make an instance of a class that has default definitions
for one of its superclasses, and there is no corresponding instance for
that class, we implicitly insert the specified default instance. If
there are more instances to choose from at that point, we report an error.
So, like we do now, we give an error at the moment of an ambigous instance
declaration. In this case, the programmer should give an explicit instance
for the superclass as well.
In your example, an error would be reported at the moment you try to make
an instance of C12, without also explicitly giving an instance for C.
This seems a simple but effective solution. But, does this raise any other
problems?
Regards,
Koen.
--
| Koen Claessen, [EMAIL PROTECTED] |
| http://www.cse.ogi.edu/~kcclaess/ |
|------------------------------------------------------|
| Visiting student at OGI, Portland, Oregon, USA. |