Make Applicative a superclass of Monad
[ghc.git] / testsuite / tests / deriving / should_fail / T3621.hs
1 {-# LANGUAGE GeneralizedNewtypeDeriving, MultiParamTypeClasses, FlexibleInstances, FunctionalDependencies, FlexibleContexts, UndecidableInstances, StandaloneDeriving #-}
2 module T3621 where
3
4 -- This one is ok, even though the deriving clause mentions 'a'
5 -- which is not a parameter of 'T'
6 class C a b
7 instance C a S
8 data S = MkS
9
10 newtype T = MkT S deriving( C a )
11
12
13 -- But this one fails, and should fail
14 class (Monad m) => MonadState s m | m -> s where
15
16 newtype State s a = State { runState :: s -> (a, s) }
17 instance Functor (State s) where {}
18 instance Applicative (State s) where {}
19 instance Monad (State s) where {}
20 instance MonadState s (State s) where {}
21
22 newtype WrappedState s a = WS { runWS :: State s a }
23 deriving (Functor, Applicative, Monad, MonadState state)
24 -- deriving (Monad)
25
26 deriving instance (MonadState state (State s))
27 => MonadState state (WrappedState s)
28
29 -- ASSERT error
30 -- deriving instance (MonadState state (State s), Monad (WrappedState s))
31 -- => MonadState s (WrappedState s)
32
33
34 -- We try
35 -- instance MonadState state (State state a)
36 -- => MonadState state (WrappedState state a)
37 --
38 -- Superclass needs (Monad (WrappedState state a))