@@ -1,5 +1,5 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2−module Metadata.Prelude (add) where
2+module Transform.AddDefaultImports (add) where
4import qualified Data.Map as Map
4import qualified Data.Map as Map
5import qualified Data.Set as Set
5import qualified Data.Set as Set
@@ -8,20 +8,42 @@ import qualified AST.Module as Module
8import qualified AST.Variable as Var
8import qualified AST.Variable as Var
11−-- DEFINITION OF THE PRELUDE
13type ImportDict =
11type ImportDict =
14 Map.Map Module.Name ([String], Var.Listing Var.Value)
12 Map.Map Module.Name ([String], Var.Listing Var.Value)
15+-- DESCRIPTION OF DEFAULT IMPORTS
17+(==>) :: a -> b -> (a,b)
17−prelude :: ImportDict
21+defaultImports :: ImportDict
18−prelude =
22+defaultImports =
19 Map.fromList $ map (\name -> (name, ([], Var.openListing))) $
23 Map.fromList $ map (\name -> (name, ([], Var.openListing))) $
20− [ -- ["Basics"]
24+ [ ["Basics"] ==> ([], Var.openListing)
25+ , ["Maybe"] ==> ([], Var.Listing [maybe] False)
26+ , ["Result"] ==> ([], Var.Listing [result] False)
27+ , ["Signal"] ==> ([], Var.Listing [signal] False)
33+ Var.ADT "Maybe" Var.openListing
38+ Var.ADT "Result" Var.openListing
43+ Var.ADT "Signal" (Var.Listing [] False)
24−-- ADDING PRELUDE TO A MODULE
46+-- ADDING DEFAULT IMPORTS TO A MODULE
26add :: Bool -> Module.Module exs body -> Module.Module exs body
48add :: Bool -> Module.Module exs body -> Module.Module exs body
27add noPrelude (Module.Module moduleName path exports imports decls) =
49add noPrelude (Module.Module moduleName path exports imports decls) =
@@ -29,7 +51,7 @@ add noPrelude (Module.Module moduleName path exports imports decls) =
30 ammendedImports =
52 ammendedImports =
31 importDictToList $
53 importDictToList $
32− foldr addImport (if noPrelude then Map.empty else prelude) imports
54+ foldr addImport (if noPrelude then Map.empty else defaultImports) imports
35importDictToList :: ImportDict -> [(Module.Name, Module.ImportMethod)]
57importDictToList :: ImportDict -> [(Module.Name, Module.ImportMethod)]