d7328c6ef62eb5490af0ca06c402c6e9f3cb36d0
[ghc.git] / testsuite / tests / deriving / should_compile / T4966.hs
1 {-# LANGUAGE DatatypeContexts #-}
2 {-# LANGUAGE EmptyDataDecls #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE UndecidableInstances #-}
5 {-# LANGUAGE OverlappingInstances #-}
6
7 module HTk.Toolkit.TreeList (getObjectFromTreeList) where
8
9 class Eq c => CItem c
10
11 -- A bizarre instance decl!
12 -- People who use instance decls like this are asking for trouble
13 instance GUIObject w => Eq w where
14 w1 == w2 = toGUIObject w1 == toGUIObject w2
15
16 data StateEntry a
17 = StateEntry (TreeListObject a) a -- Comment this 'a' out and it type checks
18 deriving Eq
19
20 -- The delicate point about this test is that we want to
21 -- infer a derived instance decl like this:
22 -- instance (CItem a, Eq a) => Eq (StateEntry a)
23 -- But note the instance decl for (Eq w) for any w!
24 -- There's a danger than we'll use that instance decl
25 -- to get the derived instance
26 -- instance (CItem a, GUIObject a) => Eq (StateEntry a)
27 -- And then that doesn't work subsequently
28
29 getObjectFromTreeList :: CItem a => StateEntry a -> Bool
30 getObjectFromTreeList state = state == state
31
32 data CItem a => TreeListObject a
33
34 instance CItem a => Eq (TreeListObject a)
35
36 class GUIObject w where
37 toGUIObject :: w -> GUIOBJECT
38
39
40 data GUIOBJECT
41
42 instance Eq GUIOBJECT where
43 (==) = undefined
44 (/=) = undefined