blob: d7328c6ef62eb5490af0ca06c402c6e9f3cb36d0 (
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
|
{-# LANGUAGE DatatypeContexts #-}
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverlappingInstances #-}
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 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 CItem a => Eq (TreeListObject a)
class GUIObject w where
toGUIObject :: w -> GUIOBJECT
data GUIOBJECT
instance Eq GUIOBJECT where
(==) = undefined
(/=) = undefined
|