Fundeps work even for unary type classes
[ghc.git] / testsuite / tests / typecheck / should_fail / tcfail157.hs
1 {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,
2 FlexibleInstances #-}
3 -- NB: *no* UndecidableInstances
4
5 -- This one (due to Oleg) made 6.4.1 go into a loop in the typechecker,
6 -- despite the lack of UndecidableInstances
7 --
8 -- The example corresponds to a type function (realized as a class E
9 -- with functional dependencies) in the context of an instance.
10 -- The function in question is
11 --
12 -- class E m a b | m a -> b
13 -- instance E m (() -> ()) (m ())
14 --
15 -- We see that the result of the function, "m ()" is smaller (in the
16 -- number of constructors) that the functions' arguments, "m" and
17 -- "() -> ()" together. Plus any type variable free in the result is also
18 -- free in at least one of the arguments. And yet it loops.
19 module ShouldFail where
20
21 class Foo m a where
22 foo :: m b -> a -> Bool
23
24 instance Foo m () where
25 foo _ _ = True
26
27 instance (E m a b, Foo m b) => Foo m (a->()) where
28 foo m f = undefined
29
30 class E m a b | m a -> b where
31 tr :: m c -> a -> b
32
33 -- There is only one instance of the class with functional dependencies
34 instance E m (() -> ()) (m ()) where
35 tr x = undefined
36
37 -- GHC(i) loops
38
39 test = foo (\f -> (f ()) :: ()) (\f -> (f ()) :: ())