89bb66ad36b8437605edab016e26138b48eb5874
[ghc-hetmet.git] / ghc / tests / typecheck / should_compile / tc125.hs
1 {-# OPTIONS -fglasgow-exts #-}
2
3 -- !!! Functional dependency test. Hugs [Apr 2001] fails to typecheck this
4 -- We should infer this type for foo
5 --      foo :: Q (S (S Z)) (S Z)
6
7 module ShouldCompile where
8
9 data Z = Z
10 data S a = S a
11
12 class Add a b c | a b -> c where add :: a -> b -> c
13
14 instance Add Z a a
15 instance Add a b c => Add (S a) b (S c)
16
17 class Mul a b c | a b -> c where mul :: a -> b -> c
18
19 instance Mul Z a Z
20 instance (Mul a b c, Add b c d) => Mul (S a) b d
21
22 data Q a b = Q a b
23
24 -- Problem here.  This is the addition of rational
25 -- numbers: (a/b) + (c/d) = (ad+bc)/bd
26
27 instance (Mul a d ad,
28           Mul b c bc,
29           Mul b d bd,
30           Add ad bc ad_bc) => Add (Q a b) (Q c d) (Q ad_bc bd)
31
32 z = Z
33 sz = S Z
34 ssz = S (S Z)
35
36 foo = add (Q sz sz) (Q sz sz)