@@ -10,14 +10,13 @@ module AST.Type
13−import Control.Arrow (second)
13+
14−import Control.Monad (liftM, liftM2, liftM3, replicateM)
14+import Control.Monad (liftM, liftM2, liftM3, liftM4, replicateM)
15import Data.Binary
15import Data.Binary
16import qualified Data.Map as Map
16import qualified Data.Map as Map
17−import Data.Text (Text)
19import qualified AST.Module.Name as ModuleName
18import qualified AST.Module.Name as ModuleName
20−import qualified AST.Variable as Var
19+import Elm.Name (Name)
21import qualified Reporting.Annotation as A
20import qualified Reporting.Annotation as A
22import qualified Reporting.Region as R
21import qualified Reporting.Region as R
@@ -31,58 +30,55 @@ type Raw =
34− = RLambda Raw Raw
33+ = RLambda Raw Raw
35− | RVar Text
34+ | RVar Name
36− | RType R.Region (Maybe Text) Text [Raw]
35+ | RType R.Region (Maybe Name) Name [Raw]
37− | RRecord [(A.Located Text, Raw)] (Maybe Raw)
36+ | RRecord [(A.Located Name, Raw)] (Maybe Raw)
39− | RTuple Raw Raw [Raw]
38+ | RTuple Raw Raw [Raw]
42data Canonical
41data Canonical
43− = Lambda Canonical Canonical
42+ = Lambda Canonical Canonical
44− | Var Text
43+ | Var Name
45− | Type Var.Canonical [Canonical]
44+ | Type ModuleName.Canonical Name [Canonical]
46− | Record [(Text, Canonical)] (Maybe Canonical)
45+ | Record (Map.Map Name Canonical) (Maybe Canonical)
48− | Tuple Canonical Canonical [Canonical]
47+ | Tuple Canonical Canonical [Canonical]
49− | Aliased Var.Canonical [(Text, Canonical)] (Aliased Canonical)
48+ | Aliased ModuleName.Canonical Name [(Name, Canonical)] (Aliased Canonical)
50− deriving (Eq, Ord)
49+ deriving (Eq, Ord)
53data Aliased t
52data Aliased t
54− = Holey t
53+ = Holey t
55− | Filled t
54+ | Filled t
56− deriving (Eq, Ord)
55+ deriving (Eq, Ord)
61− | Comparable
60+ | Comparable
62− | Appendable
61+ | Appendable
63− | CompAppend
62+ | CompAppend
64− deriving (Eq)
63+ deriving (Eq)
68-- CONSTRUCT USEFUL TYPES
67-- CONSTRUCT USEFUL TYPES
71−cmd :: ModuleName.Canonical -> Text -> Canonical
70+cmd :: ModuleName.Canonical -> Name -> Canonical
72−cmd =
71+cmd moduleName tipe =
73− effect Var.cmd
72+ Lambda
74−
73+ (Type moduleName tipe [Var "msg"])
75−
74+ (Type (ModuleName.inCore "Platform.Cmd") "Cmd" [Var "msg"])
76−sub :: ModuleName.Canonical -> Text -> Canonical
81−effect :: Var.Canonical -> ModuleName.Canonical -> Text -> Canonical
77+sub :: ModuleName.Canonical -> Name -> Canonical
82−effect effectName moduleName tipe =
78+sub moduleName tipe =
84− (Type (Var.fromModule moduleName tipe) [Var "msg"])
80+ (Type moduleName tipe [Var "msg"])
85− (Type effectName [Var "msg"])
81+ (Type (ModuleName.inCore "Platform.Sub") "Sub" [Var "msg"])
@@ -99,13 +95,13 @@ deepDealias tipe =
101 Record fields ext ->
97 Record fields ext ->
102− Record (map (second deepDealias) fields) (fmap deepDealias ext)
98+ Record (Map.map deepDealias fields) (fmap deepDealias ext)
104− Aliased _name args tipe' ->
100+ Aliased _ _ args tipe' ->
105 deepDealias (dealias args tipe')
101 deepDealias (dealias args tipe')
107− Type name args ->
103+ Type home name args ->
108− Type name (map deepDealias args)
104+ Type home name (map deepDealias args)
@@ -117,14 +113,14 @@ deepDealias tipe =
117iteratedDealias :: Canonical -> Canonical
113iteratedDealias :: Canonical -> Canonical
118iteratedDealias tipe =
114iteratedDealias tipe =
119 case tipe of
115 case tipe of
120− Aliased _ args realType ->
116+ Aliased _ _ args realType ->
121 iteratedDealias (dealias args realType)
117 iteratedDealias (dealias args realType)
127−dealias :: [(Text, Canonical)] -> Aliased Canonical -> Canonical
123+dealias :: [(Name, Canonical)] -> Aliased Canonical -> Canonical
128dealias args aliasType =
124dealias args aliasType =
129 case aliasType of
125 case aliasType of
130 Holey tipe ->
126 Holey tipe ->
@@ -134,7 +130,7 @@ dealias args aliasType =
137−dealiasHelp :: Map.Map Text Canonical -> Canonical -> Canonical
133+dealiasHelp :: Map.Map Name Canonical -> Canonical -> Canonical
138dealiasHelp typeTable tipe =
134dealiasHelp typeTable tipe =
@@ -148,13 +144,13 @@ dealiasHelp typeTable tipe =
148 Map.findWithDefault tipe x typeTable
144 Map.findWithDefault tipe x typeTable
150 Record fields ext ->
146 Record fields ext ->
151− Record (map (second go) fields) (fmap go ext)
147+ Record (Map.map go fields) (fmap go ext)
153− Aliased original args t' ->
149+ Aliased home name args t' ->
154− Aliased original (map (second go) args) t'
150+ Aliased home name (map (fmap go) args) t'
156− Type name args ->
152+ Type home name args ->
157− Type name (map go args)
153+ Type home name (map go args)
@@ -184,23 +180,24 @@ collectLambdas tipe =
184instance Binary Canonical where
180instance Binary Canonical where
185 put tipe =
181 put tipe =
186 case tipe of
182 case tipe of
187− Lambda t1 t2 -> putWord8 0 >> put t1 >> put t2
183+ Lambda a b -> putWord8 0 >> put a >> put b
188− Var x -> putWord8 1 >> put x
184+ Var a -> putWord8 1 >> put a
189− Record fs ext -> putWord8 2 >> put fs >> put ext
185+ Record a b -> putWord8 2 >> put a >> put b
190− Unit -> putWord8 3
186+ Unit -> putWord8 3
191− Tuple a b cs -> putWord8 4 >> put a >> put b >> put cs
187+ Tuple a b c -> putWord8 4 >> put a >> put b >> put c
192− Aliased var args t -> putWord8 5 >> put var >> put args >> put t
188+ Aliased a b c d -> putWord8 5 >> put a >> put b >> put c >> put d
193− Type name ts ->
189+ Type home name ts ->
195 potentialWord =
191 potentialWord =
196 length ts + 7
192 length ts + 7
198 if potentialWord <= fromIntegral (maxBound :: Word8) then
194 if potentialWord <= fromIntegral (maxBound :: Word8) then
199 do putWord8 (fromIntegral potentialWord)
195 do putWord8 (fromIntegral potentialWord)
201 mapM_ put ts
198 mapM_ put ts
203− putWord8 6 >> put name >> put ts
200+ putWord8 6 >> put home >> put name >> put ts
206 do word <- getWord8
203 do word <- getWord8
@@ -210,9 +207,9 @@ instance Binary Canonical where
210 2 -> liftM2 Record get get
207 2 -> liftM2 Record get get
211 3 -> return Unit
208 3 -> return Unit
212 4 -> liftM3 Tuple get get get
209 4 -> liftM3 Tuple get get get
213− 5 -> liftM3 Aliased get get get
210+ 5 -> liftM4 Aliased get get get get
214− 6 -> liftM2 Type get get
211+ 6 -> liftM3 Type get get get
215− n -> liftM2 Type get (replicateM (fromIntegral (n - 7)) get)
212+ n -> liftM3 Type get get (replicateM (fromIntegral (n - 7)) get)
218instance Binary t => Binary (Aliased t) where
215instance Binary t => Binary (Aliased t) where