Make Applicative a superclass of Monad
[ghc.git] / testsuite / tests / indexed-types / should_fail / T7729.hs
1 {-# LANGUAGE FlexibleContexts, TypeFamilies #-}
2 module T7729 where
3 import Control.Monad
4
5 class Monad m => PrimMonad m where
6 type PrimState m
7
8 class MonadTrans t where
9 lift :: Monad m => m a -> t m a
10
11 class (PrimMonad (BasePrimMonad m), Monad m) => MonadPrim m where
12 type BasePrimMonad m :: * -> *
13 liftPrim :: BasePrimMonad m a -> m a
14
15
16 newtype Rand m a = Rand {
17 runRand :: Maybe (m ()) -> m a
18 }
19
20 instance Monad m => Functor (Rand m) where
21 fmap = liftM
22
23 instance Monad m => Applicative (Rand m) where
24 pure = return
25 (<*>) = ap
26
27 instance (Monad m) => Monad (Rand m) where
28 return = Rand . const . return
29 (Rand rnd) >>= f = Rand $ \g -> (\x -> runRand (f x) g) =<< rnd g
30
31 instance MonadTrans Rand where
32 lift = Rand . const
33
34 instance MonadPrim m => MonadPrim (Rand m) where
35 type BasePrimMonad (Rand m) = BasePrimMonad m
36 liftPrim = liftPrim . lift