[commit: packages/hoopl] master: Get rid of `#if CABAL` conditionals (8b2e414)

git at git.haskell.org git at git.haskell.org
Mon Dec 21 22:13:52 UTC 2015


Repository : ssh://git@git.haskell.org/hoopl

On branch  : master
Link       : http://git.haskell.org/packages/hoopl.git/commitdiff/8b2e4142eb9dfb6f996204ec5613c6b1453a8cd3

>---------------------------------------------------------------

commit 8b2e4142eb9dfb6f996204ec5613c6b1453a8cd3
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sat Oct 31 12:18:37 2015 +0100

    Get rid of `#if CABAL` conditionals
    
    Those were introduced via 814d4ef37ef3b5f2dfeddced3875cbd3e8b375b1
    but there's actually a more elegant way to avoid redundant imports
    in combination with MRP-style refactoring
    (as started in 20fad2ed91cd78ed8b9bd92aae1ecfdfb8350d2f)


>---------------------------------------------------------------

8b2e4142eb9dfb6f996204ec5613c6b1453a8cd3
 changelog.md                 |  4 ++++
 src/Compiler/Hoopl/Fuel.hs   | 11 ++---------
 src/Compiler/Hoopl/Graph.hs  | 10 ++--------
 src/Compiler/Hoopl/Unique.hs | 11 ++---------
 testing/Ast2ir.hs            | 17 +++++------------
 testing/EvalMonad.hs         | 16 ++++------------
 testing/OptSupport.hs        | 15 +++++----------
 7 files changed, 24 insertions(+), 60 deletions(-)

diff --git a/changelog.md b/changelog.md
index 336df98..5603e4b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,9 @@
 # Changelog for [`hoopl` package](http://hackage.haskell.org/package/hoopl)
 
+## ...
+
+ - replace `#if CABAL` macro by no CPP at all
+
 ## 3.10.1.1 *Aug 2015*
 
  - Add #if CABAL macro to several hoopl source files such that the Cabal generated macro is not included when building in ghci
diff --git a/src/Compiler/Hoopl/Fuel.hs b/src/Compiler/Hoopl/Fuel.hs
index 5916200..66743de 100644
--- a/src/Compiler/Hoopl/Fuel.hs
+++ b/src/Compiler/Hoopl/Fuel.hs
@@ -21,14 +21,7 @@ where
 import Compiler.Hoopl.Checkpoint
 import Compiler.Hoopl.Unique
 
-#if CABAL
-#if !MIN_VERSION_base(4,8,0)
-import Control.Applicative (Applicative(..))
-#endif
-#else
-import Control.Applicative (Applicative(..))
-#endif
-
+import Control.Applicative as AP (Applicative(..))
 import Control.Monad (ap,liftM)
 
 class Monad m => FuelMonad m where
@@ -68,7 +61,7 @@ instance Monad m => Applicative (CheckingFuelMonad m) where
   (<*>) = ap
 
 instance Monad m => Monad (CheckingFuelMonad m) where
-  return = pure
+  return = AP.pure
   fm >>= k = FM (\f -> do { (a, f') <- unFM fm f; unFM (k a) f' })
 
 instance CheckpointMonad m => CheckpointMonad (CheckingFuelMonad m) where
diff --git a/src/Compiler/Hoopl/Graph.hs b/src/Compiler/Hoopl/Graph.hs
index 3d9831a..9c1cc3c 100644
--- a/src/Compiler/Hoopl/Graph.hs
+++ b/src/Compiler/Hoopl/Graph.hs
@@ -46,13 +46,7 @@ import Compiler.Hoopl.Collections
 import Compiler.Hoopl.Block
 import Compiler.Hoopl.Label
 
-#if CABAL
-#if !MIN_VERSION_base(4,8,0)
-import Control.Applicative (Applicative(..))
-#endif
-#else
-import Control.Applicative (Applicative(..))
-#endif
+import Control.Applicative as AP (Applicative(..))
 import Control.Monad (ap,liftM,liftM2)
 
 -- -----------------------------------------------------------------------------
@@ -362,7 +356,7 @@ instance Applicative VM where
   (<*>) = ap
 
 instance Monad VM where
-  return = pure
+  return = AP.pure
   m >>= k  = VM $ \visited -> let (a, v') = unVM m visited in unVM (k a) v'
 
 marked :: Label -> VM Bool
diff --git a/src/Compiler/Hoopl/Unique.hs b/src/Compiler/Hoopl/Unique.hs
index 5727fb4..79a7c7c 100644
--- a/src/Compiler/Hoopl/Unique.hs
+++ b/src/Compiler/Hoopl/Unique.hs
@@ -24,14 +24,7 @@ import Compiler.Hoopl.Collections
 import qualified Data.IntMap as M
 import qualified Data.IntSet as S
 
-#ifdef CABAL
-#if !MIN_VERSION_base(4,8,0)
-import Control.Applicative
-#endif
-#else
-import Control.Applicative
-#endif
-
+import Control.Applicative as AP
 import Control.Monad (ap,liftM)
 
 -----------------------------------------------------------------------------
@@ -127,7 +120,7 @@ instance Applicative SimpleUniqueMonad where
   (<*>) = ap
 
 instance Monad SimpleUniqueMonad where
-  return = pure
+  return = AP.pure
   m >>= k  = SUM $ \us -> let (a, us') = unSUM m us in
                               unSUM (k a) us'
 
diff --git a/testing/Ast2ir.hs b/testing/Ast2ir.hs
index cda8435..380abf5 100644
--- a/testing/Ast2ir.hs
+++ b/testing/Ast2ir.hs
@@ -1,5 +1,5 @@
 {-# OPTIONS_GHC -Wall #-}
-{-# LANGUAGE CPP, RankNTypes, ScopedTypeVariables, GADTs, EmptyDataDecls, PatternGuards, TypeFamilies, NamedFieldPuns #-}
+{-# LANGUAGE RankNTypes, ScopedTypeVariables, GADTs, EmptyDataDecls, PatternGuards, TypeFamilies, NamedFieldPuns #-}
 module Ast2ir (astToIR, IdLabelMap) where
 
 
@@ -8,13 +8,7 @@ import qualified Compiler.Hoopl as H ((<*>))
 import           Control.Monad
 import qualified Data.Map       as M
 
-#if CABAL
-#if !MIN_VERSION_base(4,8,0)
-import qualified Control.Applicative as AP (Applicative(..))
-#endif
-#else
-import qualified Control.Applicative as AP (Applicative(..))
-#endif
+import           Control.Applicative as AP (Applicative(..))
 
 import qualified Ast as A
 import qualified IR  as I
@@ -79,7 +73,7 @@ type IdLabelMap = M.Map String Label
 data LabelMapM a = LabelMapM (IdLabelMap -> I.M (IdLabelMap, a))
 
 instance Monad LabelMapM where
-  return x = LabelMapM (\m -> return (m, x))
+  return = AP.pure
   LabelMapM f1 >>= k = LabelMapM (\m -> do (m', x) <- f1 m
                                            let (LabelMapM f2) = k x
                                            f2 m')
@@ -87,11 +81,10 @@ instance Monad LabelMapM where
 instance Functor LabelMapM where
   fmap = liftM
 
-instance AP.Applicative LabelMapM where
-  pure = return
+instance Applicative LabelMapM where
+  pure x = LabelMapM (\m -> return (m, x))
   (<*>) = ap
 
-
 labelFor l = LabelMapM f
   where f m = case M.lookup l m of
                 Just l' -> return (m, l')
diff --git a/testing/EvalMonad.hs b/testing/EvalMonad.hs
index c6efc9b..4ea5f0e 100644
--- a/testing/EvalMonad.hs
+++ b/testing/EvalMonad.hs
@@ -1,23 +1,16 @@
 {-# OPTIONS_GHC -Wall #-}
-{-# LANGUAGE CPP, RankNTypes, ScopedTypeVariables, GADTs, EmptyDataDecls, PatternGuards, TypeFamilies, NamedFieldPuns , FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances #-}
+{-# LANGUAGE RankNTypes, ScopedTypeVariables, GADTs, EmptyDataDecls, PatternGuards, TypeFamilies, NamedFieldPuns , FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances #-}
 
 module EvalMonad (ErrorM, VarEnv, B, State,
                   EvalM, runProg, inNewFrame, get_proc, get_block,
                          get_var, set_var, get_heap, set_heap,
                   Event (..), event) where
 
+import Control.Applicative as AP (Applicative(..))
 import Control.Monad.Except
 import qualified Data.Map as M
 import Prelude hiding (succ)
 
-#if CABAL
-#if !MIN_VERSION_base(4,8,0)
-import Control.Applicative (Applicative(..))
-#endif
-#else
-import Control.Applicative (Applicative(..))
-#endif
-
 import Compiler.Hoopl hiding ((<*>))
 import IR
 
@@ -27,7 +20,7 @@ type InnerErrorM v = Either (State v, String)
 data EvalM v a = EvalM (State v -> InnerErrorM v (State v, a))
 
 instance Monad (EvalM v) where
-  return x = EvalM (\s -> return (s, x))
+  return = AP.pure
   EvalM f >>= k = EvalM $ \s -> do (s', x) <- f s
                                    let EvalM f' = k x
                                    f' s'
@@ -36,10 +29,9 @@ instance Functor (EvalM v) where
   fmap = liftM
 
 instance Applicative (EvalM v) where
-  pure = return
+  pure x = EvalM (\s -> return (s, x))
   (<*>) = ap
 
-
 instance MonadError String (EvalM v) where
   throwError e = EvalM (\s -> throwError (s, e))
   catchError (EvalM f) handler =
diff --git a/testing/OptSupport.hs b/testing/OptSupport.hs
index cb9826d..663400b 100644
--- a/testing/OptSupport.hs
+++ b/testing/OptSupport.hs
@@ -6,14 +6,7 @@ import Control.Monad
 import Data.Maybe
 import Prelude hiding (succ)
 
-#if CABAL
-#if !MIN_VERSION_base(4,8,0)
-import Control.Applicative (Applicative(..))
-#endif
-#else
-import Control.Applicative (Applicative(..))
-#endif
-
+import Control.Applicative as AP (Applicative(..))
 import Compiler.Hoopl hiding ((<*>))
 import IR
 
@@ -35,8 +28,10 @@ mapVE _ _       = Nothing
 
 
 data Mapped a = Old a | New a
+
 instance Monad Mapped where
-  return = Old
+  return = AP.pure
+
   Old a >>= k = k a
   New a >>= k = asNew (k a)
     where asNew (Old a)   = New a
@@ -46,7 +41,7 @@ instance Functor Mapped where
   fmap = liftM
 
 instance Applicative Mapped where
-  pure = return
+  pure = Old
   (<*>) = ap
 
 



More information about the ghc-commits mailing list