@@ -3,7 +3,6 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE UndecidableInstances #-}
55{-# LANGUAGE FlexibleInstances #-}
6−{-# LANGUAGE CPP #-}
76module Language.Haskell.Generate.Monad
87 ( Generate(..), ExpG
98 , runGenerate, newName
@@ -36,8 +35,6 @@ import Language.Haskell.Exts.SrcLoc
3635import Language.Haskell.Exts.Syntax
3736import Language.Haskell.Generate.Expression
3837
39−import Prelude
40−
4138--------------------------------------------------------------------------------
4239-- Generate expressions
4340
@@ -64,13 +61,7 @@ generateExp = prettyPrint . runExpression . fst . runGenerate
6461caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
6562caseE v alt = do
6663 v' <- v
67−#if MIN_VERSION_haskell_src_exts(1,17,0)
68− alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') Nothing) a) alt
69−#elif MIN_VERSION_haskell_src_exts(1,16,0)
70− alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') (BDecls [])) a) alt
71−#else
7264 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
73−#endif
7465 return $ Expression $ Case (runExpression v') alt'
7566
7667-- | Import a function from a module. This function is polymorphic in the type of the resulting expression,
@@ -159,6 +150,7 @@ applyE a b = wrap $ liftM (foldl1 App) $ sequence [unwrap a, unwrap b]
159150 where wrap = fmap Expression
160151 unwrap = fmap runExpression
161152
153+
162154-- | Operator for 'applyE'.
163155(<>$) :: ExpG (a -> b) -> ExpG a -> ExpG b
164156(<>$) = applyE
@@ -214,31 +206,19 @@ instance GenExp (FunRef t) where
214206
215207-- | Generate a ExportSpec for a given function item.
216208exportFun :: FunRef t -> ExportSpec
217−#if MIN_VERSION_haskell_src_exts(1,16,0) && !MIN_VERSION_haskell_src_exts(1,17,0)
218−exportFun (FunRef name) = EVar NoNamespace (UnQual name)
219−#else
220209exportFun (FunRef name) = EVar (UnQual name)
221−#endif
222210
223211-- | Add a declaration to the module. Return a reference to it that can be used to either apply the function to some values or export it.
224212addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
225213addDecl name e = ModuleM $ do
226214 let (body, mods) = runGenerate e
227−#if MIN_VERSION_haskell_src_exts(1,17,0)
228− tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) Nothing]])
229−#else
230215 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
231−#endif
232216 return $ FunRef name
233217
234218-- | Extract the Module from a module generator.
235219runModuleM :: ModuleG -> String -> Module
236220runModuleM (ModuleM act) name =
237−#if MIN_VERSION_haskell_src_exts(1,16,0)
238− Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False False Nothing Nothing Nothing) $ S.toList imps) decls
239−#else
240221 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
241−#endif
242222 where (export, (imps, decls)) = runWriter act
243223
244224-- | Generate the source code for a module.