summaryrefslogtreecommitdiff
path: root/compiler/main
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/main')
-rw-r--r--compiler/main/CmdLineParser.hs17
-rw-r--r--compiler/main/DriverPipeline.hs7
-rw-r--r--compiler/main/HscMain.hs10
-rw-r--r--compiler/main/TidyPgm.lhs7
4 files changed, 38 insertions, 3 deletions
diff --git a/compiler/main/CmdLineParser.hs b/compiler/main/CmdLineParser.hs
index 252a376432..6681186246 100644
--- a/compiler/main/CmdLineParser.hs
+++ b/compiler/main/CmdLineParser.hs
@@ -30,6 +30,9 @@ import SrcLoc
import Data.Function
import Data.List
+import Control.Monad (liftM, ap)
+import Control.Applicative (Applicative(..))
+
--------------------------------------------------------
-- The Flag and OptKind types
@@ -72,6 +75,13 @@ newtype EwM m a = EwM { unEwM :: Located String -- Current parse arg
-> Errs -> Warns
-> m (Errs, Warns, a) }
+instance Monad m => Functor (EwM m) where
+ fmap = liftM
+
+instance Monad m => Applicative (EwM m) where
+ pure = return
+ (<*>) = ap
+
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')
@@ -108,6 +118,13 @@ liftEwM action = EwM (\_ es ws -> do { r <- action; return (es, ws, r) })
-- (CmdLineP s) typically instantiates the 'm' in (EwM m) and (OptKind m)
newtype CmdLineP s a = CmdLineP { runCmdLine :: s -> (a, s) }
+instance Functor (CmdLineP s) where
+ fmap = liftM
+
+instance Applicative (CmdLineP s) where
+ pure = return
+ (<*>) = ap
+
instance Monad (CmdLineP s) where
m >>= k = CmdLineP $ \s ->
let (a, s') = runCmdLine m s
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 7c5bc90647..a6567c8c39 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -669,6 +669,13 @@ newtype CompPipeline a = P { unP :: PipeEnv -> PipeState -> IO (PipeState, a) }
evalP :: CompPipeline a -> PipeEnv -> PipeState -> IO a
evalP f env st = liftM snd $ unP f env st
+instance Functor CompPipeline where
+ fmap = liftM
+
+instance Applicative CompPipeline where
+ pure = return
+ (<*>) = ap
+
instance Monad CompPipeline where
return a = P $ \_env state -> return (state, a)
P m >>= k = P $ \env state -> do (state',a) <- m env state
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index ad1b7c503a..774f5be488 100644
--- a/compiler/main/HscMain.hs
+++ b/compiler/main/HscMain.hs
@@ -194,6 +194,13 @@ knownKeyNames = -- where templateHaskellNames are defined
newtype Hsc a = Hsc (HscEnv -> WarningMessages -> IO (a, WarningMessages))
+instance Functor Hsc where
+ fmap = liftM
+
+instance Applicative Hsc where
+ pure = return
+ (<*>) = ap
+
instance Monad Hsc where
return a = Hsc $ \_ w -> return (a, w)
Hsc m >>= k = Hsc $ \e w -> do (a, w1) <- m e w
@@ -203,9 +210,6 @@ instance Monad Hsc where
instance MonadIO Hsc where
liftIO io = Hsc $ \_ w -> do a <- io; return (a, w)
-instance Functor Hsc where
- fmap f m = m >>= \a -> return $ f a
-
runHsc :: HscEnv -> Hsc a -> IO a
runHsc hsc_env (Hsc hsc) = do
(a, w) <- hsc hsc_env emptyBag
diff --git a/compiler/main/TidyPgm.lhs b/compiler/main/TidyPgm.lhs
index d6a3da13e6..9886fe394f 100644
--- a/compiler/main/TidyPgm.lhs
+++ b/compiler/main/TidyPgm.lhs
@@ -749,6 +749,13 @@ newtype DFFV a
-> (VarSet, [Var]) -- Input State: (set, list) of free vars so far
-> ((VarSet,[Var]),a)) -- Output state
+instance Functor DFFV where
+ fmap = liftM
+
+instance Applicative DFFV where
+ pure = return
+ (<*>) = ap
+
instance Monad DFFV where
return a = DFFV $ \_ st -> (st, a)
(DFFV m) >>= k = DFFV $ \env st ->