@@ -6,7 +6,7 @@ module AST.Type
6 , Super(..)
6 , Super(..)
7 , deepDealias, iteratedDealias, dealias
7 , deepDealias, iteratedDealias, dealias
8 , collectLambdas
8 , collectLambdas
9− , tuple, cmd, sub
9+ , cmd, sub
@@ -16,7 +16,6 @@ import Data.Binary
16import qualified Data.Map as Map
16import qualified Data.Map as Map
17import Data.Text (Text)
17import Data.Text (Text)
19−import qualified AST.Helpers as Help
20import qualified AST.Module.Name as ModuleName
19import qualified AST.Module.Name as ModuleName
21import qualified AST.Variable as Var
20import qualified AST.Variable as Var
22import qualified Reporting.Annotation as A
21import qualified Reporting.Annotation as A
@@ -34,8 +33,10 @@ type Raw =
35 = RLambda Raw Raw
34 = RLambda Raw Raw
36 | RVar Text
35 | RVar Text
37− | RType (A.Located Var.Raw) [Raw]
36+ | RType R.Region (Maybe Text) Text [Raw]
38 | RRecord [(A.Located Text, Raw)] (Maybe Raw)
37 | RRecord [(A.Located Text, Raw)] (Maybe Raw)
39+ | RTuple Raw Raw [Raw]
41data Canonical
42data Canonical
@@ -43,6 +44,8 @@ data Canonical
43 | Var Text
44 | Var Text
44 | Type Var.Canonical [Canonical]
45 | Type Var.Canonical [Canonical]
45 | Record [(Text, Canonical)] (Maybe Canonical)
46 | Record [(Text, Canonical)] (Maybe Canonical)
48+ | Tuple Canonical Canonical [Canonical]
46 | Aliased Var.Canonical [(Text, Canonical)] (Aliased Canonical)
49 | Aliased Var.Canonical [(Text, Canonical)] (Aliased Canonical)
47 deriving (Eq, Ord)
50 deriving (Eq, Ord)
@@ -65,15 +68,6 @@ data Super
65-- CONSTRUCT USEFUL TYPES
68-- CONSTRUCT USEFUL TYPES
68−tuple :: R.Region -> [Raw] -> Raw
72− Var.Raw (Help.makeTuple (length types))
74− A.A region (RType (A.A region name) types)
77cmd :: ModuleName.Canonical -> Text -> Canonical
71cmd :: ModuleName.Canonical -> Text -> Canonical
79 effect Var.cmd
73 effect Var.cmd
@@ -113,6 +107,12 @@ deepDealias tipe =
113 Type name args ->
107 Type name args ->
114 Type name (map deepDealias args)
108 Type name (map deepDealias args)
114+ Tuple (deepDealias a) (deepDealias b) (map deepDealias cs)
117iteratedDealias :: Canonical -> Canonical
117iteratedDealias :: Canonical -> Canonical
118iteratedDealias tipe =
118iteratedDealias tipe =
@@ -156,6 +156,12 @@ dealiasHelp typeTable tipe =
156 Type name args ->
156 Type name args ->
157 Type name (map go args)
157 Type name (map go args)
163+ Tuple (go a) (go b) (map go cs)
161-- COLLECT LAMBDAS
167-- COLLECT LAMBDAS
@@ -178,29 +184,23 @@ collectLambdas tipe =
178instance Binary Canonical where
184instance Binary Canonical where
179 put tipe =
185 put tipe =
180 case tipe of
186 case tipe of
182− putWord8 0 >> put t1 >> put t2
187+ Lambda t1 t2 -> putWord8 0 >> put t1 >> put t2
185− putWord8 1 >> put x
188+ Var x -> putWord8 1 >> put x
188− putWord8 2 >> put fs >> put ext
189+ Record fs ext -> putWord8 2 >> put fs >> put ext
189−
190+ Unit -> putWord8 3
190− Aliased var args t ->
191+ Tuple a b cs -> putWord8 4 >> put a >> put b >> put cs
191− putWord8 3 >> put var >> put args >> put t
192+ Aliased var args t -> putWord8 5 >> put var >> put args >> put t
193− Type name ts ->
193+ Type name ts ->
195 potentialWord =
195 potentialWord =
196− length ts + 5
196+ length ts + 7
198 if potentialWord <= fromIntegral (maxBound :: Word8) then
198 if potentialWord <= fromIntegral (maxBound :: Word8) then
199 do putWord8 (fromIntegral potentialWord)
199 do putWord8 (fromIntegral potentialWord)
201 mapM_ put ts
201 mapM_ put ts
203− putWord8 4 >> put name >> put ts
203+ putWord8 6 >> put name >> put ts
206 do word <- getWord8
206 do word <- getWord8
@@ -208,9 +208,11 @@ instance Binary Canonical where
208 0 -> liftM2 Lambda get get
208 0 -> liftM2 Lambda get get
209 1 -> liftM Var get
209 1 -> liftM Var get
210 2 -> liftM2 Record get get
210 2 -> liftM2 Record get get
212+ 4 -> liftM3 Tuple get get get
211− 3 -> liftM3 Aliased get get get
213+ 5 -> liftM3 Aliased get get get
212− 4 -> liftM2 Type get get
214+ 6 -> liftM2 Type get get
213− n -> liftM2 Type get (replicateM (fromIntegral (n - 5)) get)
215+ n -> liftM2 Type get (replicateM (fromIntegral (n - 7)) get)
216instance Binary t => Binary (Aliased t) where
218instance Binary t => Binary (Aliased t) where