
I would like to state that a class Sup is exhaustively broken down in two subclasses Sub1 and Sub2 (meaning, for every instance of Sub1 and every instance of Sub2, the methods in Sup apply). I try to code this as: instance Sub1 x => Sup x instance Sub2 x => Sup x And get the (expected) error message ExhaustiveClass.hs:22:0: Duplicate instance declarations: ExhaustiveClass.hs:22:0: instance (Sub1 x) => Sup x ExhaustiveClass.hs:25:0: instance (Sub2 x) => Sup x (I have allowed overlapping instances, undecidable instances) Is there another way of achieving this? Any help appreciated! Andrew ----------------- complete code I tried with: class Sub1 a where op1 :: a -> a class Sub2 a where op2 :: a -> a -> a class Sup a where op3 :: a -> Bool instance Sub1 Int where op1 = id instance Sub2 Float where op2 x y = y instance Sub1 x => Sup x where op3 _ = True instance Sub2 x => Sup x where op3 _ = False But get Andrew U. Frank Professor, Head of Department Geoinformation and Cartography E127 phone: +43 1 588 01 12710 TU Vienna secr. +43 1 588 01 12700 Gusshausstrasse 27-29 fax +43 1 588 01 12799 A-1040 Vienna Austria cellular phone +43 676 41925 72 http://www.geoinfo.tuwien.ac.at/persons/frank/frank.html skype:AndrewUFrank

In article <200508110639.j7B6dSqP004876@mx02.kabsi.at>,
"Frank"
I would like to state that a class Sup is exhaustively broken down in two subclasses Sub1 and Sub2 (meaning, for every instance of Sub1 and every instance of Sub2, the methods in Sup apply).
I try to code this as:
instance Sub1 x => Sup x instance Sub2 x => Sup x
And get the (expected) error message ExhaustiveClass.hs:22:0: Duplicate instance declarations: ExhaustiveClass.hs:22:0: instance (Sub1 x) => Sup x ExhaustiveClass.hs:25:0: instance (Sub2 x) => Sup x (I have allowed overlapping instances, undecidable instances)
Is there another way of achieving this? Any help appreciated!
Andrew
----------------- complete code I tried with: class Sub1 a where op1 :: a -> a
class Sub2 a where op2 :: a -> a -> a
class Sup a where op3 :: a -> Bool
instance Sub1 Int where op1 = id instance Sub2 Float where op2 x y = y
instance Sub1 x => Sup x where op3 _ = True
instance Sub2 x => Sup x where op3 _ = False
Try this: class Sup a where op3 :: a -> Bool class (Sup a) => Sub1 a where op1 :: a -> a class (Sup a) => Sub2 a where op2 :: a -> a -> a instance Sup Int where op3 _ = True instance Sup Float where op3 _ = False instance Sub1 Int where op1 = id instance Sub2 Float where op2 x y = y -- Ashley Yakeley, Seattle WA
participants (2)
-
Ashley Yakeley
-
Frank