Complete work on new OVERLAPPABLE/OVERLAPPING pragmas (Trac #9242)
[ghc.git] / testsuite / tests / indexed-types / should_fail / T4485.hs
1 -- The behavior of type-inference and OverlappingInstances has changed
2 -- between GHC 6.12 and GHC 7.0 such that the following code
3 -- type-checks under 6.12, but not 7.0rc2. I assume this change has
4 -- something to do with the new type checker in GHC 7, but it is not
5 -- clear to me if this change in behavior is intended. Nor am I clear
6 -- how to achieve something similar to the old behavior. This is
7 -- preventing HSP (and by extension, happstack) from migrating to GHC
8 -- 7. I reported this earlier on the mailing lists, but I have further
9 -- simplied the test case here.
10
11 {-# LANGUAGE TypeFamilies, MultiParamTypeClasses
12 , FlexibleContexts, FlexibleInstances, UndecidableInstances
13 , TypeSynonymInstances, GeneralizedNewtypeDeriving
14 #-}
15 module XMLGenerator where
16
17 newtype XMLGenT m a = XMLGenT (m a)
18 deriving (Functor, Monad)
19
20 class Monad m => XMLGen m where
21 type XML m
22 data Child m
23 genElement :: String -> XMLGenT m (XML m)
24
25 class XMLGen m => EmbedAsChild m c where
26 asChild :: c -> XMLGenT m [Child m]
27
28 instance {-# OVERLAPPING #-} (EmbedAsChild m c, m1 ~ m) => EmbedAsChild m (XMLGenT m1 c)
29
30 instance {-# OVERLAPPABLE #-} (XMLGen m, XML m ~ x) => EmbedAsChild m x
31
32 data Xml = Xml
33 data IdentityT m a = IdentityT (m a)
34 instance Monad (IdentityT m)
35 instance XMLGen (IdentityT m) where
36 type XML (IdentityT m) = Xml
37
38 data Identity a = Identity a
39 instance Monad Identity
40
41 instance {-# OVERLAPPING #-} EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
42
43 data FooBar = FooBar
44
45 instance {-# OVERLAPPING #-} EmbedAsChild (IdentityT IO) FooBar where
46 asChild b = asChild $ (genElement "foo")
47 -- asChild :: FooBar -> XMLGenT (XMLGenT (IdentityT IO) [Child (IdentitiyT IO)])
48
49 {- ---------- Deriving the constraints ----------
50 asChild :: EmbedAsChild m c => c -> XMLGenT m [Child m]
51 genElement :: XMLGen m => String -> XMLGenT m (XML m)
52
53 Wanted: EmbedAsChild m c, with m = IdentityT IO
54 c = XMLGenT meta (XML meta)
55 XMLGen meta
56
57 ie EmbedAsChild (IdentityT IO) (XMLGen meta (XML meta)
58 XMLGen meta
59
60 We have instances
61 EmbedAsChild (IdentityT IO) FooBar
62 EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
63 EmbedAsChild m (XMLGenT m1 c)
64 EmbedAsChild m x
65 -}