@@ -2,6 +2,7 @@
22module AST.Module where
33
44import Data.Binary
5+import qualified Data.List as List
56import qualified Data.Map as Map
67import Control.Applicative ((<$>),(<*>))
78
@@ -10,6 +11,9 @@ import qualified AST.Declaration as Decl
1011import qualified AST.Type as Type
1112import qualified AST.Variable as Var
1213
14+import AST.PrettyPrint
15+import Text.PrettyPrint as P
16+
1317import qualified Elm.Internal.Version as Version
1418
1519data Module exs body = Module
@@ -24,8 +28,8 @@ data CanonicalBody = CanonicalBody
2428 { program :: Canonical.Expr
2529 , types :: Types
2630 , fixities :: [(Decl.Assoc, Int, String)]
27− , aliases :: [Alias]
28− , datatypes :: [ADT]
31+ , aliases :: Aliases
32+ , datatypes :: ADTs
2933 , ports :: [String]
3034 }
3135
@@ -35,16 +39,16 @@ type CanonicalModule = Module [Var.Value] CanonicalBody
3539
3640type Interfaces = Map.Map String Interface
3741
38−type Types = Map.Map String (Type.Type Var.Canonical)
39−type ADT = ( String, [String], [(String, [Type.Type Var.Canonical])] )
40−type Alias = (String, [String], Type.Type Var.Canonical )
42+type Types = Map.Map String (Type.Type Var.Canonical)
43+type ADTs = Map.Map String ( [String], [(String, [Type.Type Var.Canonical])] )
44+type Aliases = Map.Map String ( [String], Type.Type Var.Canonical )
4145
4246data Interface = Interface
4347 { iVersion :: Version.Version
4448 , iTypes :: Types
4549 , iImports :: [(String, ImportMethod)]
46− , iAdts :: [ADT]
47− , iAliases :: [Alias]
50+ , iAdts :: ADTs
51+ , iAliases :: Aliases
4852 , iFixities :: [(Decl.Assoc, Int, String)]
4953 , iPorts :: [String]
5054 }
@@ -96,29 +100,15 @@ instance Binary ImportMethod where
96100 1 -> Open <$> get
97101 _ -> error "Error reading valid ImportMethod type from serialized string"
98102
99−{-
100−data Module port def = Module
101− { name :: [String]
102− , exports :: Var.Listing Var.Value
103− , imports :: [(String, ImportMethod)]
104− , decls :: [Declaration' port def]
105− }
106−
107−instance (Pretty port, Pretty def) => Pretty (Module port def) where
108− pretty (Module names exs ims decls) =
109− P.vcat [modul, P.text "", prettyImports, P.text "", prettyDecls]
103+instance (Pretty exs, Pretty body) => Pretty (Module exs body) where
104+ pretty (Module names _ exs ims body) =
105+ P.vcat [modul, P.text "", prettyImports, P.text "", pretty body]
110106 where
111− modul = P.text "module" <+> name <+> prettyExports <+> P.text "where"
107+ modul = P.text "module" <+> name <+> pretty exs <+> P.text "where"
112108 name = P.text (List.intercalate "." names)
113109
114− prettyExports
115− | Var._open exs = P.empty
116− | otherwise = pretty exs
117−
118110 prettyImports = P.vcat $ map prettyMethod ims
119111
120− prettyDecls = P.sep $ map pretty decls
121−
122112prettyMethod :: (String, ImportMethod) -> Doc
123113prettyMethod (name, method) =
124114 case method of
@@ -127,5 +117,3 @@ prettyMethod (name, method) =
127117 | otherwise -> P.text "as" <+> P.text alias
128118
129119 Open listing -> pretty listing
130−
131−-}