[Haskell-cafe] Overlapping instances
Frank
frank at geoinfo.tuwien.ac.at
Thu Aug 11 02:39:31 EDT 2005
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
More information about the Haskell-Cafe
mailing list