summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_compile/tc216.hs
blob: 4a23f3df7fb359e8e978d508fc47f74e92c75792 (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
33
34
35
36
37
38
39
{-# LANGUAGE UndecidableInstances, FlexibleInstances,
             MultiParamTypeClasses, FunctionalDependencies #-}

-- Test for trac #816
-- GHC's typechecker loops when trying to type this, resulting in a
-- context stack overflow.

{- Maybe this should typecheck:

   Given: Foo x y, Bar y z
   Wanted: Foo x beta, Bar beta z

If we happened to process (Foo x beta) first we 
might generate the extra equality beta~y, and we are good

If we process (Bar beta z) first, we end up in an infinite
loop, using the (Bar x z) instance repeatedly.

If instead we'd had
   class (F x ~ y) => Foo x y where
     type F x
     foo :: x -> y

Then after canonicalising we get
     Given: Foo x y, Bar y z, F x ~ y
     Wanted: Foo x beta, Bar beta z
-}

module ShouldCompile where

class Foo x y | x -> y where
 foo :: x -> y

class Bar x z where
 bar :: x -> z -> Int

instance (Foo x y, Bar y z) => Bar x z where
 bar x z = bar (foo x) z