b48e8206f281d5f49555f774b80176c231ada0bb
[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 , OverlappingInstances
15 #-}
16 module XMLGenerator where
17
18 newtype XMLGenT m a = XMLGenT (m a)
19 deriving (Functor, Monad)
20
21 class Monad m => XMLGen m where
22 type XML m
23 data Child m
24 genElement :: String -> XMLGenT m (XML m)
25
26 class XMLGen m => EmbedAsChild m c where
27 asChild :: c -> XMLGenT m [Child m]
28
29 instance (EmbedAsChild m c, m1 ~ m) => EmbedAsChild m (XMLGenT m1 c)
30
31 instance (XMLGen m, XML m ~ x) => EmbedAsChild m x
32
33 data Xml = Xml
34 data IdentityT m a = IdentityT (m a)
35 instance Monad (IdentityT m)
36 instance XMLGen (IdentityT m) where
37 type XML (IdentityT m) = Xml
38
39 data Identity a = Identity a
40 instance Monad Identity
41
42 instance EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
43
44 data FooBar = FooBar
45
46 instance EmbedAsChild (IdentityT IO) FooBar where
47 asChild b = asChild $ (genElement "foo")
48 -- asChild :: FooBar -> XMLGenT (XMLGenT (IdentityT IO) [Child (IdentitiyT IO)])
49
50 {- ---------- Deriving the constraints ----------
51 asChild :: EmbedAsChild m c => c -> XMLGenT m [Child m]
52 genElement :: XMLGen m => String -> XMLGenT m (XML m)
53
54 Wanted: EmbedAsChild m c, with m = IdentityT IO
55 c = XMLGenT meta (XML meta)
56 XMLGen meta
57
58 ie EmbedAsChild (IdentityT IO) (XMLGen meta (XML meta)
59 XMLGen meta
60
61 We have instances
62 EmbedAsChild (IdentityT IO) FooBar
63 EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
64 EmbedAsChild m (XMLGenT m1 c)
65 EmbedAsChild m x
66 -}