@@ -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
@@ -61,7 +62,11 @@ generateExp = prettyPrint . runExpression . fst . runGenerate
6162caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
6263caseE v alt = do
6364 v' <- v
65+#if MIN_VERSION_haskell_src_exts(1,16,0)
66+ alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') (BDecls [])) a) alt
67+#else
6468 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
69+#endif
6570 return $ Expression $ Case (runExpression v') alt'
6671
6772-- | Import a function from a module. This function is polymorphic in the type of the resulting expression,
@@ -205,7 +210,11 @@ instance GenExp (FunRef t) where
205210
206211-- | Generate a ExportSpec for a given function item.
207212exportFun :: FunRef t -> ExportSpec
213+#if MIN_VERSION_haskell_src_exts(1,16,0)
214+exportFun (FunRef name) = EVar NoNamespace (UnQual name)
215+#else
208216exportFun (FunRef name) = EVar (UnQual name)
217+#endif
209218
210219-- | 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.
211220addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
@@ -217,7 +226,11 @@ addDecl name e = ModuleM $ do
217226-- | Extract the Module from a module generator.
218227runModuleM :: ModuleG -> String -> Module
219228runModuleM (ModuleM act) name =
229+#if MIN_VERSION_haskell_src_exts(1,16,0)
230+ Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False False Nothing Nothing Nothing) $ S.toList imps) decls
231+#else
220232 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
233+#endif
221234 where (export, (imps, decls)) = runWriter act
222235
223236-- | Generate the source code for a module.