@@ -74,6 +74,27 @@ moduleFileName opts name = do
7474ensureDirectory :: FilePath -> IO ()
7575ensureDirectory = createDirectoryIfMissing True . takeDirectory
7676
77+ -- | Compile the full import list,
78+ -- with special handling for the @Prelude@ as prescribed by 'Options'.
79+ compileImportsWithPrelude
80+ :: Options -> String -> Imports -> TCM [Hs. ImportDecl () ]
81+ compileImportsWithPrelude opts mod imps = do
82+ -- if the prelude is supposed to be implicit,
83+ -- or the prelude imports have been fixed in the config file,
84+ -- we remove it from the list of imports
85+ let filteredImps =
86+ if not preludeImplicit && isNothing preludeImports
87+ then imps
88+ else filter ((/= Hs. prelude_mod () ) . importModule) imps
89+
90+ -- then we try to add it back
91+ if (not preludeImplicit && isNothing preludeImports) || null preludeHiding
92+ then compileImports mod filteredImps
93+ else (preludeImportDecl preOpts: ) <$> compileImports mod filteredImps
94+ where
95+ preOpts@ PreludeOpts {.. } = optPrelude opts
96+
97+ -- | Render the @.hs@ module as a 'String' and write it to a file.
7798writeModule :: Options -> ModuleEnv -> IsMain -> TopLevelModuleName
7899 -> [(CompiledDef , CompileOutput )] -> TCM ModuleRes
79100writeModule opts _ isMain m outs = do
@@ -89,24 +110,8 @@ writeModule opts _ isMain m outs = do
89110 let unlines' [] = []
90111 unlines' ss = unlines ss ++ " \n "
91112
92- let preOpts@ PreludeOpts {.. } = optPrelude opts
93-
94- -- if the prelude is supposed to be implicit,
95- -- or the prelude imports have been fixed in the config file,
96- -- we remove it from the list of imports
97- let filteredImps =
98- if not preludeImplicit && isNothing preludeImports
99- then imps
100- else filter ((/= Hs. prelude_mod () ) . importModule) imps
101-
102- -- then we try to add it back
103- let autoImportList =
104- if (not preludeImplicit && isNothing preludeImports) || null preludeHiding
105- then compileImports mod filteredImps
106- else (preludeImportDecl preOpts: ) <$> compileImports mod filteredImps
107-
108- -- Add automatic imports
109- autoImports <- (unlines' . map Hs. prettyShowImportDecl) <$> autoImportList
113+ autoImports <- unlines' . map Hs. prettyShowImportDecl
114+ <$> compileImportsWithPrelude opts mod imps
110115
111116 -- The comments make it hard to generate and pretty print a full module
112117 hsFile <- moduleFileName opts m
0 commit comments