1 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}

2 {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,

3 FlexibleInstances, UndecidableInstances #-}

4 -- UndecidableInstances because (L a b) is no smaller than (C a b)

6 -- This one shows up another rather subtle functional-dependecy

7 -- case. The error is:

8 --

9 -- Could not deduce (C a b') from the context (C a b)

10 -- arising from the superclasses of an instance declaration at Foo.hs:8:0

11 -- Probable fix: add (C a b') to the instance declaration superclass context

12 -- In the instance declaration for `C (Maybe a) a'

13 --

14 -- Since L is a superclass of the (sought) constraint (C a b'), you might

15 -- think that we'd generate the superclasses (L a b') and (L a b), and now

16 -- the fundep will force b=b'. But GHC is very cautious about generating

17 -- superclasses when doing context reduction for instance declarations,

18 -- because of the danger of superclass loops.

19 --

20 -- So, today, this program fails. It's trivial to fix by adding a fundep for C

21 -- class (G a, L a b) => C a b | a -> b

23 -- Note: Sept 08: when fixing Trac #1470, tc138 started working!

24 -- This test is a very strange one (fundeps, undecidable instances),

25 -- so I'm just marking it as "should-succeed". It's not very clear to

26 -- me what the "right" answer should be; when we have the type equality

27 -- story more worked out we might want to think about that.

31 class G a