@@ -3,6 +3,7 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE UndecidableInstances #-}
55{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE CPP #-}
67module Language.Haskell.Generate.Monad
78 ( Generate(..), ExpG
89 , runGenerate, newName
@@ -35,6 +36,8 @@ import Language.Haskell.Exts.SrcLoc
3536import Language.Haskell.Exts.Syntax
3637import Language.Haskell.Generate.Expression
3738
39+import Prelude
40+
3841--------------------------------------------------------------------------------
3942-- Generate expressions
4043
@@ -61,7 +64,13 @@ generateExp = prettyPrint . runExpression . fst . runGenerate
6164caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
6265caseE v alt = do
6366 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
6472 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
73+#endif
6574 return $ Expression $ Case (runExpression v') alt'
6675
6776-- | Import a function from a module. This function is polymorphic in the type of the resulting expression,
@@ -150,7 +159,6 @@ applyE a b = wrap $ liftM (foldl1 App) $ sequence [unwrap a, unwrap b]
150159 where wrap = fmap Expression
151160 unwrap = fmap runExpression
152161
153−
154162-- | Operator for 'applyE'.
155163(<>$) :: ExpG (a -> b) -> ExpG a -> ExpG b
156164(<>$) = applyE
@@ -206,19 +214,31 @@ instance GenExp (FunRef t) where
206214
207215-- | Generate a ExportSpec for a given function item.
208216exportFun :: 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
209220exportFun (FunRef name) = EVar (UnQual name)
221+#endif
210222
211223-- | 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.
212224addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
213225addDecl name e = ModuleM $ do
214226 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
215230 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
231+#endif
216232 return $ FunRef name
217233
218234-- | Extract the Module from a module generator.
219235runModuleM :: ModuleG -> String -> Module
220236runModuleM (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
221240 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
241+#endif
222242 where (export, (imps, decls)) = runWriter act
223243
224244-- | Generate the source code for a module.