[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / compiler / tests / typecheck / should_fail / tcfail043.hs
1 -- The translation of this program should assign only one dictionary to
2 -- the function search (an Ord dictionary). Instead, it assigns two.
3 -- The output produced currently displays this.
4
5 -- 10/12/92:  This program is actually erroneous.  The pattern-binding for
6 -- search falls under the monomorphism restriction, and there is no
7 -- call to search which might fix its type.  So there should be a complaint.
8 -- But the actual error message is horrible:
9 -- 
10 -- "bug001.hs", line 26: Ambiguous overloading:
11 --     class "Ord_", type "a" (at a use of an overloaded identifier: gt)
12 --     class "Eq_", type "a" (at a use of an overloaded identifier: eq)
13
14
15
16 class Eq_ a where
17  eq :: a -> a -> Bool
18
19 instance Eq_ Int where
20  eq = eqIntEq
21
22 instance (Eq_ a) => Eq_ [a] where
23  eq = \ xs ys -> 
24      if (null xs) 
25         then (null ys)
26         else if (null ys) 
27                 then False
28                 else and (eq (hd xs) (hd ys)) (eq (tl xs) (tl ys))
29
30 class (Eq_ a) => Ord_ a where
31  gt :: a -> a -> Bool
32
33 instance Ord_ Int where
34  gt = ordIntGt
35
36 search 
37  = \ a bs -> if gt (hd bs) a
38                 then False 
39                 else if eq a (hd bs) then True else search a (tl bs)
40
41 and :: Bool -> Bool -> Bool
42 and True True = True
43
44 hd :: [a] -> a
45 hd (a:as) = a
46
47 tl :: [a] -> [a]
48 tl (a:as) = as
49
50 ordIntGt :: Int -> Int -> Bool
51 ordIntGt 2 3 = True
52
53 eqIntEq :: Int -> Int -> Bool
54 eqIntEq  2 3 = True
55
56 null :: [a] -> Bool
57 null [] = True
58
59
60
61 {-
62
63 ===============================================
64 Main.Eq__INST_PreludeBuiltin.Int =
65     let
66       AbsBinds [] [] [(eq, eq)]
67           {- nonrec -}
68           {-# LINE 2 "test3.hs" -}
69
70           eq :: PreludeBuiltin.Int -> PreludeBuiltin.Int -> PreludeCore.Bool
71           eq = Main.eqIntEq
72     in ({-dict-} [] [eq])
73
74 Main.Eq__INST_PreludeBuiltin.List =
75     /\ t135 ->
76         \{-dict-} _dict138 ->
77             let
78               {- nonrec -}
79               _dict136 = {-singleDict-} _dict138
80               {- nonrec -}
81               _dict129 = {-singleDict-} _dict136
82               AbsBinds [] [] [(eq, eq)]
83                   {- nonrec -}
84
85                   _dict133 =
86                       Main.Eq__INST_PreludeBuiltin.List
87                           [t135] [{-singleDict-} _dict136]
88                   {- nonrec -}
89                   {-# LINE 5 "test3.hs" -}
90
91                   eq :: [t135] -> [t135] -> PreludeCore.Bool
92                   eq = \ xs ys -> 
93
94 if (Main.null t135) xs then
95                                       (Main.null t135) ys
96                                   else
97
98                                       if (Main.null t135) ys then
99                                           PreludeCore.False
100                                       else
101
102                                           Main.and
103
104
105                                               ((Main.Eq_.eq t135 _dict129)
106
107
108                                                    ((Main.hd t135) xs)
109                                                    ((Main.hd t135) ys))
110                                               
111
112
113
114
115
116 (Main.Eq_.eq [t135] _dict133)
117
118
119
120                                                    ((Main.tl t135) xs)
121                                                    ((Main.tl t135) ys))
122             in ({-dict-} [] [eq])
123 Main.Ord__INST_PreludeBuiltin.Int =
124     let
125       {- nonrec -}
126       _dict142 = Main.Eq__INST_PreludeBuiltin.Int [] []
127       AbsBinds [] [] [(gt, gt)]
128           {- nonrec -}
129           {-# LINE 16 "test3.hs" -}
130
131           gt :: PreludeBuiltin.Int -> PreludeBuiltin.Int -> PreludeCore.Bool
132           gt = Main.ordIntGt
133     in ({-dict-} [_dict142] [gt])
134
135 Main.Eq_.eq = /\ a -> \{-classdict-} [] [eq] -> eq
136
137 Main.Ord_.gt = /\ a -> \{-classdict-} [_dict56] [gt] -> gt
138
139 Main.Ord__TO_Main.Eq_ = /\ a -> \{-classdict-} [_dict58] [gt] -> ???_dict58???
140
141 AbsBinds [t60] [] [(hd, Main.hd)]
142     {- nonrec -}
143
144
145
146     hd :: [t60] -> t60
147     hd (a PreludeBuiltin.: as)
148                = a
149
150 AbsBinds [t68] [] [(tl, Main.tl)]
151     {- nonrec -}
152
153
154
155
156     tl :: [t68] -> [t68]
157     tl (a PreludeBuiltin.: as)
158                = as
159
160
161 AbsBinds [t91] [_dict85, _dict88] [(search, Main.search)]
162     {- rec -}
163     {-# LINE 19 "test3.hs" -}
164
165
166     search :: t91 -> [t91] -> PreludeCore.Bool
167     search
168         = \ a bs -> 
169
170
171 if (Main.Ord_.gt t91 _dict85) ((Main.hd t91) bs) a then
172                         PreludeCore.False
173                     else
174
175                         if (Main.Eq_.eq t91 _dict88) a ((Main.hd t91) bs) then
176                             PreludeCore.True
177                         else
178
179                             search a ((Main.tl t91) bs)
180 AbsBinds [] [] [(and, Main.and)]
181     {- nonrec -}
182     and :: PreludeCore.Bool -> PreludeCore.Bool -> PreludeCore.Bool
183     and PreludeCore.True PreludeCore.True
184                 = PreludeCore.True
185 AbsBinds [] [] [(ordIntGt, Main.ordIntGt)]
186     {- nonrec -}
187     _dict97 = PreludeCore.Num_INST_PreludeBuiltin.Int [] []
188     {- nonrec -}
189     _dict98 = PreludeCore.Eq_INST_PreludeBuiltin.Int [] []
190     {- nonrec -}
191     _dict100 = PreludeCore.Num_INST_PreludeBuiltin.Int [] []
192     {- nonrec -}
193     _dict101 = PreludeCore.Eq_INST_PreludeBuiltin.Int [] []
194     {- nonrec -}
195
196
197
198     ordIntGt :: PreludeBuiltin.Int -> PreludeBuiltin.Int -> PreludeCore.Bool
199     ordIntGt
200         2 3 = PreludeCore.True
201 AbsBinds [] [] [(eqIntEq, Main.eqIntEq)]
202     {- nonrec -}
203     _dict105 = PreludeCore.Num_INST_PreludeBuiltin.Int [] []
204     {- nonrec -}
205     _dict106 = PreludeCore.Eq_INST_PreludeBuiltin.Int [] []
206     {- nonrec -}
207     _dict108 = PreludeCore.Num_INST_PreludeBuiltin.Int [] []
208     {- nonrec -}
209     _dict109 = PreludeCore.Eq_INST_PreludeBuiltin.Int [] []
210     {- nonrec -}
211
212     eqIntEq :: PreludeBuiltin.Int -> PreludeBuiltin.Int -> PreludeCore.Bool
213     eqIntEq
214         2 3 = PreludeCore.True
215
216
217 AbsBinds [t112] [] [(null, Main.null)]
218     {- nonrec -}
219
220     null :: [t112] -> PreludeCore.Bool
221     null [] = PreludeCore.True
222 -}