Lower precedence for {-# UNPACK #-}
[ghc.git] / testsuite / tests / typecheck / should_fail / fd-loop.hs
1 {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
2
3 -- Here's a nice example of a fundep loop, correctly
4 -- rejected by the undecidable-instance check.
5 -- See comments below.
6
7 module FDLoop where
8
9 class C a b | a -> b where f :: a -> b
10 newtype T a = T a
11
12 instance (C a b, Eq b) => Eq (T a) where (==) = undefined
13
14 g x = (undefined :: d -> d -> d -> ()) (T x) (f x) (undefined :: Eq e => e)
15
16 {- Analysis
17
18 f :: C a b => a -> b
19 x :: a
20 b ~ T a
21 need: C a b
22 b ~ e
23 need: Eq e
24
25 Hence need (C a (T a), Eq (T a))
26 Apply instance for Eq
27 = (C a (T a), C a g, Eq g)
28 Apply functional dependency: g ~ T a
29 = (C a (T a), C a (T a), Eq (T a))
30 And now we are back where we started
31 -}
32