@@ -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,
@@ -205,19 +214,31 @@ instance GenExp (FunRef t) where
205214
206215-- | Generate a ExportSpec for a given function item.
207216exportFun :: 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
208220exportFun (FunRef name) = EVar (UnQual name)
221+#endif
209222
210223-- | 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.
211224addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
212225addDecl name e = ModuleM $ do
213226 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
214230 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
231+#endif
215232 return $ FunRef name
216233
217234-- | Extract the Module from a module generator.
218235runModuleM :: ModuleG -> String -> Module
219236runModuleM (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
220240 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
241+#endif
221242 where (export, (imps, decls)) = runWriter act
222243
223244-- | Generate the source code for a module.