on master help sign in
Move RawType and CanonicalType into AST.Type
commit4cd751457e76c7c755cc978452d7b2efc19cebc3 authorEvan Czaplicki <info@elm-lang.org> dateSun 13 Apr 2014, 11:26 (13 years ago) parent6dfa748
7 files changed+27−27
compiler/AST/Declaration.hs+1−1 compiler/AST/Expression/Canonical.hs+2−2 compiler/AST/Expression/Source.hs+3−3 compiler/AST/Expression/Valid.hs+2−2 compiler/AST/Module.hs+3−3 compiler/AST/Type.hs+7−5 compiler/Parse/Type.hs+9−11
compiler/AST/Declaration.hs+1−1
@@ -22,7 +22,7 @@ data Assoc = L | N | R
2222 deriving (Eq)
2323
2424data RawPort
25− = PPAnnotation String (T.Type Var.Raw)
25+ = PPAnnotation String T.RawType
2626 | PPDef String Source.Expr
2727 deriving (Show)
2828
compiler/AST/Expression/Canonical.hs+2−2
@@ -5,7 +5,7 @@ module AST.Expression.Canonical where
55import AST.PrettyPrint
66import Text.PrettyPrint as P
77import qualified AST.Expression.General as General
8−import AST.Type (Type)
8+import AST.Type (CanonicalType)
99import qualified AST.Annotation as Annotation
1010import qualified AST.Pattern as Pattern
1111import qualified AST.Variable as Var
@@ -17,7 +17,7 @@ they came from.
1717type Expr = General.Expr Annotation.Region Def Var.Canonical
1818type Expr' = General.Expr' Annotation.Region Def Var.Canonical
1919
20−data Def = Definition (Pattern.Pattern Var.Canonical) Expr (Maybe (Type Var.Canonical))
20+data Def = Definition Pattern.CanonicalPattern Expr (Maybe CanonicalType)
2121 deriving (Show)
2222
2323instance Pretty Def where
compiler/AST/Expression/Source.hs+3−3
@@ -5,7 +5,7 @@ module AST.Expression.Source where
55import AST.PrettyPrint
66import Text.PrettyPrint as P
77import qualified AST.Expression.General as General
8−import AST.Type (Type)
8+import AST.Type (RawType)
99import qualified AST.Variable as Var
1010import qualified AST.Annotation as Annotation
1111import qualified AST.Pattern as Pattern
@@ -19,8 +19,8 @@ type Expr = General.Expr Annotation.Region Def Var.Raw
1919type Expr' = General.Expr' Annotation.Region Def Var.Raw
2020
2121data Def
22− = Definition (Pattern.Pattern Var.Raw) Expr
23− | TypeAnnotation String (Type Var.Raw)
22+ = Definition Pattern.RawPattern Expr
23+ | TypeAnnotation String RawType
2424 deriving (Show)
2525
2626instance Pretty Def where
compiler/AST/Expression/Valid.hs+2−2
@@ -5,7 +5,7 @@ module AST.Expression.Valid where
55import AST.PrettyPrint
66import Text.PrettyPrint as P
77import qualified AST.Expression.General as General
8−import AST.Type (Type)
8+import AST.Type (RawType)
99import qualified AST.Variable as Var
1010import qualified AST.Annotation as Annotation
1111import qualified AST.Pattern as Pattern
@@ -18,7 +18,7 @@ them into a Def that is easier to work with in later phases of compilation.
1818type Expr = General.Expr Annotation.Region Def Var.Raw
1919type Expr' = General.Expr' Annotation.Region Def Var.Raw
2020
21−data Def = Definition (Pattern.Pattern Var.Raw) Expr (Maybe (Type Var.Raw))
21+data Def = Definition Pattern.RawPattern Expr (Maybe RawType)
2222 deriving (Show)
2323
2424instance Pretty Def where
compiler/AST/Module.hs+3−3
@@ -39,9 +39,9 @@ type CanonicalModule = Module [Var.Value] CanonicalBody
3939
4040type Interfaces = Map.Map String Interface
4141
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 )
42+type Types = Map.Map String Type.CanonicalType
43+type ADTs = Map.Map String ( [String], [(String, [Type.CanonicalType])] )
44+type Aliases = Map.Map String ( [String], Type.CanonicalType )
4545
4646data Interface = Interface
4747 { iVersion :: Version.Version
compiler/AST/Type.hs+7−5
@@ -5,7 +5,6 @@ import Control.Applicative ((<$>), (<*>))
55import Data.Binary
66import qualified Data.Map as Map
77
8−import AST.Variable (Raw(Raw))
98import qualified AST.Variable as Var
109import AST.PrettyPrint
1110import qualified AST.Helpers as Help
@@ -19,6 +18,9 @@ data Type var
1918 | Aliased Var.Canonical (Type var)
2019 deriving (Eq,Show)
2120
21+type RawType = Type Var.Raw
22+type CanonicalType = Type Var.Canonical
23+
2224fieldMap :: [(String,a)] -> Map.Map String [a]
2325fieldMap fields =
2426 foldl (\r (x,t) -> Map.insertWith (++) x [t] r) Map.empty fields
@@ -26,11 +28,11 @@ fieldMap fields =
2628recordOf :: [(String, Type var)] -> Type var
2729recordOf fields = Record fields Nothing
2830
29−listOf :: Type Raw -> Type Raw
30−listOf t = Data (Raw "_List") [t]
31+listOf :: RawType -> RawType
32+listOf t = Data (Var.Raw "_List") [t]
3133
32−tupleOf :: [Type Raw] -> Type Raw
33−tupleOf ts = Data (Raw $ "_Tuple" ++ show (length ts)) ts
34+tupleOf :: [RawType] -> RawType
35+tupleOf ts = Data (Var.Raw $ "_Tuple" ++ show (length ts)) ts
3436
3537instance (Var.ToString var, Pretty var) => Pretty (Type var) where
3638 pretty tipe =
compiler/Parse/Type.hs+9−11
@@ -9,21 +9,19 @@ import qualified AST.Type as T
99import qualified AST.Variable as Var
1010import Parse.Helpers
1111
12−type RawType = T.Type Var.Raw
13−
14−tvar :: IParser RawType
12+tvar :: IParser T.RawType
1513tvar = T.Var <$> lowVar <?> "type variable"
1614
17−list :: IParser RawType
15+list :: IParser T.RawType
1816list = T.listOf <$> braces expr
1917
20−tuple :: IParser RawType
18+tuple :: IParser T.RawType
2119tuple = do ts <- parens (commaSep expr)
2220 return $ case ts of
2321 [t] -> t
2422 _ -> T.tupleOf ts
2523
26−record :: IParser RawType
24+record :: IParser T.RawType
2725record =
2826 do char '{' ; whitespace
2927 rcrd <- extended <|> normal
@@ -46,15 +44,15 @@ record =
4644capTypeVar :: IParser String
4745capTypeVar = intercalate "." <$> dotSep1 capVar
4846
49−constructor0 :: IParser RawType
47+constructor0 :: IParser T.RawType
5048constructor0 =
5149 do name <- capTypeVar
5250 return (T.Data (Var.Raw name) [])
5351
54−term :: IParser RawType
52+term :: IParser T.RawType
5553term = list <|> tuple <|> record <|> tvar <|> constructor0
5654
57−app :: IParser RawType
55+app :: IParser T.RawType
5856app =
5957 do name <- capTypeVar <|> try tupleCtor <?> "type constructor"
6058 args <- spacePrefix term
@@ -64,7 +62,7 @@ app =
6462 n <- length <$> parens (many (char ','))
6563 return $ "_Tuple" ++ show (if n == 0 then 0 else n+1)
6664
67−expr :: IParser RawType
65+expr :: IParser T.RawType
6866expr =
6967 do t1 <- app <|> term
7068 arr <- optionMaybe $ try (whitespace >> arrow)
@@ -72,6 +70,6 @@ expr =
7270 Just _ -> T.Lambda t1 <$> (whitespace >> expr)
7371 Nothing -> return t1
7472
75−constructor :: IParser (String, [RawType])
73+constructor :: IParser (String, [T.RawType])
7674constructor = (,) <$> (capTypeVar <?> "another type constructor")
7775 <*> spacePrefix term