Testsuite: tabs -> spaces [skip ci]
[ghc.git] / testsuite / tests / typecheck / should_run / tcrun018.hs
1 {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
2
3 class Monad m => C1 m x
4
5 class (Monad m, C1 m x) => C2 m x
6 where
7 c2 :: x -> m x
8
9 class C1 m x => C3 m x
10 where
11 c3 :: x -> m x
12
13 instance Monad m => C1 m Bool
14
15 instance C2 Maybe Bool
16 where
17 c2 = return
18
19 instance C3 Maybe Bool
20 where
21 c3 = return
22
23
24 main = do { print (c2 True :: Maybe Bool) ;
25 print (c3 True :: Maybe Bool) }
26
27 ------------------------------------------------------------------------
28 {- Here's the email from Ralf Laemmel
29 reporting a bug in Hugs
30
31 1. If you evaluate "test",
32 then you get as expected "Just True".
33
34 2. Now remove the "Monad M" constraint
35 in the class C2. [giving the class C3]
36 This is of course legal and semantics-preserving
37 since the monad constraints is implied by C1
38 anyway.
39
40 3. Now evaluate "test" again. Oops, it diverges.
41
42 I did this Hugs Version February 2001 under Solaris
43 and Linux. Command line option -98 is needed of course.
44 Funny enough, if CTRL-C the evaluation of "test"
45 and you try it the second time (without reloading
46 anything etc.), then you see "Program error: {_Gc Black
47 Hole}". Of course, there is no such black hole.
48
49 I extracted the above fragment from a huge problem.
50 The scheme is the following. It seems have to do
51 with multi-parameter classes. It definitely has to
52 do with multi-layered class hierarchies where one
53 class has a class-wide superclass, as C2 has C1 in
54 the example. It seems that the superclass is
55 properly propagated during type-inference/checking
56 but it is not properly propagated, as for as code
57 determination in overloading resolution.
58
59 Please, let me know if I can be of further assistance.
60 I am actually amazed how general this scheme is
61 (3 classes, 2 parameters). How does it come that it
62 was not detected much earlier.
63
64 Anyway, good luck,
65 Ralf
66
67
68 P.S.: I have more problems in a larger application.
69 Certain overloaded expressions diverge. I can recover
70 from that usually by using explicit function types
71 for top-level functions, where again -- as in C1 above
72 -- I repeat some constraints which are derivable. I was
73 not able to extract a simple program for that problem.
74 But I would be glad to help you by checking if the
75 problem is gone after you did the bug fix.
76
77
78 --
79 Dr.-Ing. Ralf Laemmel
80 CWI & VU, Amsterdam, The Netherlands
81 http://www.cwi.nl/~ralf/
82 http://www.cs.vu.nl/~ralf/
83
84 -}