SCC analysis for instances as well as types/classes
[ghc.git] / testsuite / tests / typecheck / should_compile / T10592.hs
1 {-# LANGUAGE TypeFamilies #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE UndecidableSuperClasses #-}
4
5 module T10592 where
6
7 import Prelude (Bool(True,False),Integer,Ordering)
8 import qualified Prelude
9
10 --------------------
11 -- class hierarchy
12
13 class Boolean (Logic a) => Eq a where
14 type Logic a :: *
15 (==) :: a -> a -> Logic a
16
17 (/=) :: a -> a -> Logic a
18 a/=b = not (a==b)
19
20 class Eq a => POrd a where
21 inf :: a -> a -> a
22
23 class POrd a => MinBound a where
24 minBound :: a
25
26 class POrd a => Lattice a where
27 sup :: a -> a -> a
28
29 class (Lattice a, MinBound a) => Bounded a where
30 maxBound :: a
31
32 class Bounded a => Complemented a where
33 not :: a -> a
34
35 class Bounded a => Heyting a where
36 infixr 3 ==>
37 (==>) :: a -> a -> a
38
39 class (Complemented a, Heyting a) => Boolean a
40
41 (||) :: Boolean a => a -> a -> a
42 (||) = sup
43
44 (&&) :: Boolean a => a -> a -> a
45 (&&) = inf
46
47 --------------------
48 -- Bool instances
49 -- (these work fine)
50
51 instance Eq Bool where
52 type Logic Bool = Bool
53 (==) = (Prelude.==)
54
55 instance POrd Bool where
56 inf True True = True
57 inf _ _ = False
58
59 instance MinBound Bool where
60 minBound = False
61
62 instance Lattice Bool where
63 sup False False = False
64 sup _ _ = True
65
66 instance Bounded Bool where
67 maxBound = True
68
69 instance Complemented Bool where
70 not True = False
71 not False = True
72
73 instance Heyting Bool where
74 False ==> _ = True
75 True ==> a = a
76
77 instance Boolean Bool
78
79 --------------------
80 -- Integer instances
81 -- (these work fine)
82
83 instance Eq Integer where
84 type Logic Integer = Bool
85 (==) = (Prelude.==)
86
87 instance POrd Integer where
88 inf = Prelude.min
89
90 instance Lattice Integer where
91 sup = Prelude.max
92
93 --------------------
94 -- function instances
95 -- (these cause GHC to loop)
96
97 instance Eq b => Eq (a -> b) where
98 type Logic (a -> b) = a -> Logic b
99 f==g = \a -> f a == g a
100
101 instance POrd b => POrd (a -> b) where
102 inf f g = \a -> inf (f a) (g a)
103
104 instance MinBound b => MinBound (a -> b) where
105 minBound = \_ -> minBound
106
107 instance Lattice b => Lattice (a -> b) where
108 sup f g = \a -> sup (f a) (g a)
109
110 instance Bounded b => Bounded (a -> b) where
111 maxBound = \_ -> maxBound
112
113 instance Complemented b => Complemented (a -> b) where
114 not f = \a -> not (f a)
115
116 instance Heyting b => Heyting (a -> b) where
117 f ==> g = \a -> f a ==> g a
118
119 instance Boolean b => Boolean (a -> b)