summaryrefslogtreecommitdiff
path: root/compiler/main
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/main')
-rw-r--r--compiler/main/Annotations.hs6
-rw-r--r--compiler/main/CmdLineParser.hs5
-rw-r--r--compiler/main/GhcMonad.hs11
-rw-r--r--compiler/main/HscTypes.hs5
-rw-r--r--compiler/main/PipelineMonad.hs5
-rw-r--r--compiler/main/TidyPgm.hs6
6 files changed, 13 insertions, 25 deletions
diff --git a/compiler/main/Annotations.hs b/compiler/main/Annotations.hs
index f6d5a1cb12..82d80aae43 100644
--- a/compiler/main/Annotations.hs
+++ b/compiler/main/Annotations.hs
@@ -4,6 +4,7 @@
-- (c) The University of Glasgow 2006
-- (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
--
+{-# LANGUAGE DeriveFunctor #-}
module Annotations (
-- * Main Annotation data types
Annotation(..), AnnPayload,
@@ -49,14 +50,11 @@ data AnnTarget name
= NamedTarget name -- ^ We are annotating something with a name:
-- a type or identifier
| ModuleTarget Module -- ^ We are annotating a particular module
+ deriving (Functor)
-- | The kind of annotation target found in the middle end of the compiler
type CoreAnnTarget = AnnTarget Name
-instance Functor AnnTarget where
- fmap f (NamedTarget nm) = NamedTarget (f nm)
- fmap _ (ModuleTarget mod) = ModuleTarget mod
-
-- | Get the 'name' of an annotation target if it exists.
getAnnTargetName_maybe :: AnnTarget name -> Maybe name
getAnnTargetName_maybe (NamedTarget nm) = Just nm
diff --git a/compiler/main/CmdLineParser.hs b/compiler/main/CmdLineParser.hs
index 6763aed128..d2cc56f033 100644
--- a/compiler/main/CmdLineParser.hs
+++ b/compiler/main/CmdLineParser.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
+{-# LANGUAGE DeriveFunctor #-}
-------------------------------------------------------------------------------
--
@@ -166,9 +167,7 @@ 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
+ deriving (Functor)
instance Applicative (CmdLineP s) where
pure a = CmdLineP $ \s -> (a, s)
diff --git a/compiler/main/GhcMonad.hs b/compiler/main/GhcMonad.hs
index f72cacc7ef..846744c439 100644
--- a/compiler/main/GhcMonad.hs
+++ b/compiler/main/GhcMonad.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE CPP, RankNTypes #-}
+{-# LANGUAGE CPP, DeriveFunctor, RankNTypes #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
-- -----------------------------------------------------------------------------
--
@@ -90,7 +90,7 @@ logWarnings warns = do
-- | A minimal implementation of a 'GhcMonad'. If you need a custom monad,
-- e.g., to maintain additional state consider wrapping this monad or using
-- 'GhcT'.
-newtype Ghc a = Ghc { unGhc :: Session -> IO a }
+newtype Ghc a = Ghc { unGhc :: Session -> IO a } deriving (Functor)
-- | The Session is a handle to the complete state of a compilation
-- session. A compilation session consists of a set of modules
@@ -98,9 +98,6 @@ newtype Ghc a = Ghc { unGhc :: Session -> IO a }
-- interactive evaluation, and various caches.
data Session = Session !(IORef HscEnv)
-instance Functor Ghc where
- fmap f m = Ghc $ \s -> f `fmap` unGhc m s
-
instance Applicative Ghc where
pure a = Ghc $ \_ -> return a
g <*> m = do f <- g; a <- m; return (f a)
@@ -158,13 +155,11 @@ reifyGhc act = Ghc $ act
--
-- Note that the wrapped monad must support IO and handling of exceptions.
newtype GhcT m a = GhcT { unGhcT :: Session -> m a }
+ deriving (Functor)
liftGhcT :: m a -> GhcT m a
liftGhcT m = GhcT $ \_ -> m
-instance Functor m => Functor (GhcT m) where
- fmap f m = GhcT $ \s -> f `fmap` unGhcT m s
-
instance Applicative m => Applicative (GhcT m) where
pure x = GhcT $ \_ -> pure x
g <*> m = GhcT $ \s -> unGhcT g s <*> unGhcT m s
diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index eb9877b096..2749073ff1 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -5,6 +5,7 @@
-}
{-# LANGUAGE CPP, ScopedTypeVariables #-}
+{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
@@ -231,9 +232,7 @@ data HscStatus
-- The Hsc monad: Passing an environment and warning state
newtype Hsc a = Hsc (HscEnv -> WarningMessages -> IO (a, WarningMessages))
-
-instance Functor Hsc where
- fmap = liftM
+ deriving (Functor)
instance Applicative Hsc where
pure a = Hsc $ \_ w -> return (a, w)
diff --git a/compiler/main/PipelineMonad.hs b/compiler/main/PipelineMonad.hs
index bbb1a17b65..d152d04530 100644
--- a/compiler/main/PipelineMonad.hs
+++ b/compiler/main/PipelineMonad.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE NamedFieldPuns #-}
-- | The CompPipeline monad and associated ops
--
@@ -22,13 +23,11 @@ import FileCleanup (TempFileLifetime)
import Control.Monad
newtype CompPipeline a = P { unP :: PipeEnv -> PipeState -> IO (PipeState, a) }
+ deriving (Functor)
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 a = P $ \_env state -> return (state, a)
(<*>) = ap
diff --git a/compiler/main/TidyPgm.hs b/compiler/main/TidyPgm.hs
index d0e813a403..4f9c8c856f 100644
--- a/compiler/main/TidyPgm.hs
+++ b/compiler/main/TidyPgm.hs
@@ -4,7 +4,7 @@
\section{Tidying up Core}
-}
-{-# LANGUAGE CPP, ViewPatterns #-}
+{-# LANGUAGE CPP, DeriveFunctor, ViewPatterns #-}
module TidyPgm (
mkBootModDetailsTc, tidyProgram, globaliseAndTidyId
@@ -751,9 +751,7 @@ newtype DFFV a
-- we don't want to record these as free vars
-> (VarSet, [Var]) -- Input State: (set, list) of free vars so far
-> ((VarSet,[Var]),a)) -- Output state
-
-instance Functor DFFV where
- fmap = liftM
+ deriving (Functor)
instance Applicative DFFV where
pure a = DFFV $ \_ st -> (st, a)