Query regarding GHC handling of overlapping instances.
Keean Schupke
k.schupke@imperial.ac.uk
Tue, 09 Sep 2003 13:12:57 +0100
I have been doing some work recently which involves classes with
overlapping instances... for example
class Test x y where
test :: x -> y
instance Test (a b) (c b) where
test =
instance Test (a b) (a b) where
test =
This gives an overlapping instance error - which cannot be avoided with
-fallow-overlapping-instances.
However - it is fairly obvious that the first case 'a' cannot be unified
with 'c' or it would be a type error, therefore
the cases do not overlap... Is this a bug in ghc, is it easily fixable -
or am I confused?
This leads on to my second point: A request for a new feature (if it
cannot be done with existing features). I would like
to be able to specify class non-membership. Say we have orthogonal
classes A and B, I can see situations where definitions like the
following would be useful:
instance (A a,B a) => C a ...
instance (A a, (not B) a) => C a ...
perhaps the complete set of boolean operators would make sense for
completeness allowing:
instance ((A a) and ((B a) or (C a))) => D a ...
Obviously functions defined in classes B and C would not be usable in
the function definitions of D because
we are uncertain of membership of B and C individually.
Regards,
Keean Schupke.