Make Applicative a superclass of Monad
[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, Applicative, 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 Functor (IdentityT m)
35 instance Applicative (IdentityT m)
36 instance Monad (IdentityT m)
37 instance XMLGen (IdentityT m) where
38 type XML (IdentityT m) = Xml
39
40 data Identity a = Identity a
41 instance Functor Identity
42 instance Applicative Identity
43 instance Monad Identity
44
45 instance {-# OVERLAPPING #-} EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
46
47 data FooBar = FooBar
48
49 instance {-# OVERLAPPING #-} EmbedAsChild (IdentityT IO) FooBar where
50 asChild b = asChild $ (genElement "foo")
51 -- asChild :: FooBar -> XMLGenT (XMLGenT (IdentityT IO) [Child (IdentitiyT IO)])
52
53 {- ---------- Deriving the constraints ----------
54 asChild :: EmbedAsChild m c => c -> XMLGenT m [Child m]
55 genElement :: XMLGen m => String -> XMLGenT m (XML m)
56
57 Wanted: EmbedAsChild m c, with m = IdentityT IO
58 c = XMLGenT meta (XML meta)
59 XMLGen meta
60
61 ie EmbedAsChild (IdentityT IO) (XMLGen meta (XML meta)
62 XMLGen meta
63
64 We have instances
65 EmbedAsChild (IdentityT IO) FooBar
66 EmbedAsChild (IdentityT IO) (XMLGenT Identity ())
67 EmbedAsChild m (XMLGenT m1 c)
68 EmbedAsChild m x
69 -}