[project @ 1999-01-23 18:10:00 by sof]
[ghc-hetmet.git] / ghc / tests / codeGen / should_run / cg017.hs
1 -- !!! test of cyclic default methods
2 --
3 class Foo a where
4     op1 :: Fractional b => a -> b -> Bool
5     op2 :: Fractional b => a -> b -> Bool
6     op3 :: Fractional b => a -> b -> Bool
7     op4 :: Fractional b => a -> b -> Bool
8     op5 :: Fractional b => a -> b -> Bool
9     op6 :: Fractional b => a -> b -> Bool
10
11     -- each depends on the next:
12     op1 a b = not (op2 a b)
13     op2 a b = not (op3 a b)
14     op3 a b = not (op4 a b)
15     op4 a b = not (op5 a b)
16     op5 a b = not (op6 a b)
17     op6 a b = not (op1 a b)
18
19 -- now some instance decls to break the cycle:
20 instance Foo Int where
21     op1 a b = a == 42
22
23 instance Foo Char where
24     op1 a b = a == 'c'
25
26 instance Foo a => Foo [a] where
27     op1 a b = null a
28
29 -- try it:
30 main = do
31     putStr (show (op2 (3::Int)    3.14159))
32     putStr (show (op2 'X'         3.14159))
33     putStr (show (op2 ([]::[Char])3.14159))