summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/tcfail157.hs
blob: 74f02ed1e5eb327d16fad09af97a2d9ca7da36fe (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 MultiParamTypeClasses, FunctionalDependencies,
             FlexibleInstances #-}
-- NB: *no* UndecidableInstances

-- This one (due to Oleg) made 6.4.1 go into a loop in the typechecker,
-- despite the lack of UndecidableInstances
--
-- The example corresponds to a type function (realized as a class E 
-- with functional dependencies) in the context of an instance. 
-- The function in question is
--
--	class E m a b | m a -> b
--	instance E m (() -> ()) (m ())
--
-- We see that the result of the function, "m ()" is smaller (in the
-- number of constructors) that the functions' arguments, "m" and
-- "() -> ()" together. Plus any type variable free in the result is also
-- free in at least one of the arguments. And yet it loops.
module ShouldFail where

class Foo m a where
    foo :: m b -> a -> Bool

instance Foo m () where
    foo _ _ = True

instance (E m a b, Foo m b) => Foo m (a->()) where
    foo m f = undefined

class E m a b | m a -> b where
    tr :: m c -> a -> b

-- There is only one instance of the class with functional dependencies
instance E m (() -> ()) (m ()) where
    tr x = undefined

-- GHC(i) loops

test = foo (\f -> (f ()) :: ()) (\f -> (f ()) :: ())