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