Commit 3c8cb7f4 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Remove some redundant definitions/constraints

Starting with GHC 7.10 and base-4.8, `Monad` implies `Applicative`,
which allows to simplify some definitions to exploit the superclass
relationship. This a first refactoring to that end.
parent 2f923ce2
......@@ -127,7 +127,6 @@ splitUniqSupply4 us = (us1, us2, us3, us4)
newtype UniqSM result = USM { unUSM :: UniqSupply -> (# result, UniqSupply #) }
instance Monad UniqSM where
return = pure
(>>=) = thenUs
(>>) = (*>)
......
......@@ -222,7 +222,6 @@ instance Monad CmmLint where
case m dflags of
Left e -> Left e
Right a -> unCL (k a) dflags
return = pure
instance HasDynFlags CmmLint where
getDynFlags = CmmLint (\dflags -> Right dflags)
......
......@@ -1008,7 +1008,6 @@ instance Applicative TE where
instance Monad TE where
TE m >>= k = TE $ \s -> case m s of (a, s') -> unTE (k a) s'
return = pure
te_lbl :: CLabel -> TE ()
te_lbl lbl = TE $ \(temps,lbls) -> ((), (temps, Map.insert lbl () lbls))
......
......@@ -89,7 +89,6 @@ instance Applicative CmmParse where
instance Monad CmmParse where
(>>=) = thenExtFC
return = pure
instance HasDynFlags CmmParse where
getDynFlags = EC (\_ _ d -> do dflags <- getDynFlags
......
......@@ -77,7 +77,6 @@ import UniqSupply
import FastString
import Outputable
import qualified Control.Applicative as A
import Control.Monad
import Data.List
import Prelude hiding( sequence, succ )
......@@ -117,13 +116,12 @@ newtype FCode a = FCode (CgInfoDownwards -> CgState -> (# a, CgState #))
instance Functor FCode where
fmap f (FCode g) = FCode $ \i s -> case g i s of (# a, s' #) -> (# f a, s' #)
instance A.Applicative FCode where
instance Applicative FCode where
pure = returnFC
(<*>) = ap
instance Monad FCode where
(>>=) = thenFC
return = A.pure
{-# INLINE thenC #-}
{-# INLINE thenFC #-}
......
......@@ -1576,7 +1576,6 @@ instance Applicative LintM where
(<*>) = ap
instance Monad LintM where
return = pure
fail err = failWithL (text err)
m >>= k = LintM (\ env errs ->
let (res, errs') = unLintM m env errs in
......
......@@ -1055,7 +1055,6 @@ instance Applicative TM where
(<*>) = ap
instance Monad TM where
return = pure
(TM m) >>= k = TM $ \ env st ->
case m env st of
(r1,fv1,st1) ->
......
......@@ -170,7 +170,6 @@ instance Applicative Assembler where
(<*>) = ap
instance Monad Assembler where
return = pure
NullAsm x >>= f = f x
AllocPtr p k >>= f = AllocPtr p (k >=> f)
AllocLit l k >>= f = AllocLit l (k >=> f)
......
......@@ -1684,7 +1684,6 @@ instance Applicative BcM where
instance Monad BcM where
(>>=) = thenBc
(>>) = (*>)
return = pure
instance HasDynFlags BcM where
getDynFlags = BcM $ \st -> return (st, hsc_dflags (bcm_hsc_env st))
......
......@@ -87,7 +87,6 @@ instance Applicative CvtM where
(<*>) = ap
instance Monad CvtM where
return = pure
(CvtM m) >>= k = CvtM $ \loc -> case m loc of
Left err -> Left err
Right (loc',v) -> unCvtM (k v) loc'
......
......@@ -218,7 +218,6 @@ instance Applicative LlvmM where
(<*>) = ap
instance Monad LlvmM where
return = pure
m >>= f = LlvmM $ \env -> do (x, env') <- runLlvmM m env
runLlvmM (f x) env'
......
......@@ -103,7 +103,6 @@ instance Monad m => Applicative (EwM m) where
instance Monad m => Monad (EwM m) where
(EwM f) >>= k = EwM (\l e w -> do (e', w', r) <- f l e w
unEwM (k r) l e' w')
return = pure
runEwM :: EwM m a -> m (Errs, Warns, a)
runEwM action = unEwM action (panic "processArgs: no arg yet") emptyBag emptyBag
......@@ -151,7 +150,6 @@ instance Monad (CmdLineP s) where
let (a, s') = runCmdLine m s
in runCmdLine (k a) s'
return = pure
getCmdLineState :: CmdLineP s s
getCmdLineState = CmdLineP $ \s -> (s,s)
......
......@@ -104,7 +104,6 @@ instance Applicative Ghc where
g <*> m = do f <- g; a <- m; return (f a)
instance Monad Ghc where
return = pure
m >>= g = Ghc $ \s -> do a <- unGhc m s; unGhc (g a) s
instance MonadIO Ghc where
......@@ -168,11 +167,10 @@ instance Applicative m => Applicative (GhcT m) where
pure x = GhcT $ \_ -> pure x
g <*> m = GhcT $ \s -> unGhcT g s <*> unGhcT m s
instance (Applicative m, Monad m) => Monad (GhcT m) where
return = pure
instance Monad m => Monad (GhcT m) where
m >>= k = GhcT $ \s -> do a <- unGhcT m s; unGhcT (k a) s
instance (Applicative m, MonadIO m) => MonadIO (GhcT m) where
instance MonadIO m => MonadIO (GhcT m) where
liftIO ioA = GhcT $ \_ -> liftIO ioA
instance ExceptionMonad m => ExceptionMonad (GhcT m) where
......
......@@ -228,7 +228,6 @@ instance Applicative Hsc where
(<*>) = ap
instance Monad Hsc where
return = pure
Hsc m >>= k = Hsc $ \e w -> do (a, w1) <- m e w
case k a of
Hsc k' -> k' e w1
......
......@@ -31,7 +31,6 @@ instance Applicative CompPipeline where
(<*>) = ap
instance Monad CompPipeline where
return = pure
P m >>= k = P $ \env state -> do (state',a) <- m env state
unP (k a) env state'
......
......@@ -775,7 +775,6 @@ instance Applicative DFFV where
(<*>) = ap
instance Monad DFFV where
return = pure
(DFFV m) >>= k = DFFV $ \env st ->
case m env st of
(st',a) -> case k a of
......
......@@ -983,7 +983,6 @@ instance Applicative CmmOptM where
(<*>) = ap
instance Monad CmmOptM where
return = pure
(CmmOptM f) >>= g =
CmmOptM $ \dflags this_mod imports ->
case f dflags this_mod imports of
......
......@@ -94,7 +94,6 @@ instance Applicative NatM where
instance Monad NatM where
(>>=) = thenNat
return = pure
thenNat :: NatM a -> (a -> NatM b) -> NatM b
......
......@@ -57,7 +57,6 @@ instance Applicative (RegM freeRegs) where
instance Monad (RegM freeRegs) where
m >>= k = RegM $ \s -> case unReg m s of { (# s, a #) -> unReg (k a) s }
return = pure
instance HasDynFlags (RegM a) where
getDynFlags = RegM $ \s -> (# s, ra_DynFlags s #)
......
......@@ -1783,7 +1783,6 @@ instance Applicative P where
(<*>) = ap
instance Monad P where
return = pure
(>>=) = thenP
fail = failP
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment