summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/fd-loop.hs
blob: ef89914e9be7611765c18de5998be5bbbda63a89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}

-- Here's a nice example of a fundep loop, correctly
-- rejected by the undecidable-instance check.
-- See comments below.

module FDLoop where

class C a b | a -> b where f :: a -> b
newtype T a = T a

instance (C a b, Eq b) => Eq (T a) where (==) = undefined

g x = (undefined :: d -> d -> d -> ()) (T x) (f x) (undefined :: Eq e => e)

{-    Analysis

   f :: C a b => a -> b
   x :: a
   b ~ T a
   need: C a b
   b ~ e
   need: Eq e

Hence need (C a (T a), Eq (T a))
Apply instance for Eq
     = (C a (T a), C a g, Eq g)
Apply functional dependency: g ~ T a
     = (C a (T a), C a (T a), Eq (T a))
And now we are back where we started
-}