@@ -134,9 +134,10 @@ addExport exports name =
135desugarImports :: [Module] -> Either String [Module]
135desugarImports :: [Module] -> Either String [Module]
136desugarImports modules = do
136desugarImports modules = do
137+ let modules' = importPrelude `map` modules
137− unfilteredExports <- findExports modules
138+ unfilteredExports <- findExports modules'
138− exports <- foldM filterModuleExports unfilteredExports modules
139+ exports <- foldM filterModuleExports unfilteredExports modules'
139− mapM (renameInModule' unfilteredExports exports) modules
140+ mapM (renameInModule' unfilteredExports exports) modules'
142 -- Filters the exports for a module in the global exports environment so that only explicitly
143 -- Filters the exports for a module in the global exports environment so that only explicitly
@@ -155,6 +156,19 @@ desugarImports modules = do
155 imports <- resolveImports env m
156 imports <- resolveImports env m
156 renameInModule imports env (elaborateExports exps m)
157 renameInModule imports env (elaborateExports exps m)
160+-- Add an import declaration for the Prelude to a module if it does not already explicitly import
163+importPrelude :: Module -> Module
164+importPrelude m@(Module mn decls exps) =
165+ if isPreludeImport `any` decls then m
166+ else Module mn (preludeImport : decls) exps
168+ isPreludeImport (ImportDeclaration (ModuleName [ProperName "Prelude"]) _ _) = True
169+ isPreludeImport _ = False
170+ preludeImport = ImportDeclaration (ModuleName [ProperName "Prelude"]) Nothing Nothing
159-- Rethrow an error with the name of the current module in the case of a failure
173-- Rethrow an error with the name of the current module in the case of a failure