Merge non-moving garbage collector
[ghc.git] / testsuite / tests / typecheck / should_compile / tc125.hs
1 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
2 {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,
3 FlexibleInstances, UndecidableInstances #-}
4 -- UndecidableInstances now needed because the Coverage Condition fails
5
6 -- !!! Functional dependency test. Hugs [Apr 2001] fails to typecheck this
7 -- We should infer this type for foo
8 -- foo :: Q (S (S Z)) (S Z)
9
10 module ShouldCompile where
11
12 data Z = Z
13 data S a = S a
14
15 class Add a b c | a b -> c where add :: a -> b -> c
16
17 instance Add Z a a
18 instance Add a b c => Add (S a) b (S c)
19
20 class Mul a b c | a b -> c where mul :: a -> b -> c
21
22 instance Mul Z a Z
23 instance (Mul a b c, Add b c d) => Mul (S a) b d
24
25 data Q a b = Q a b
26
27 -- Problem here. This is the addition of rational
28 -- numbers: (a/b) + (c/d) = (ad+bc)/bd
29
30 instance (Mul a d ad,
31 Mul b c bc,
32 Mul b d bd,
33 Add ad bc ad_bc) => Add (Q a b) (Q c d) (Q ad_bc bd)
34
35 z = Z
36 sz = S Z
37 ssz = S (S Z)
38
39 foo = add (Q sz sz) (Q sz sz)