@@ -63,9 +63,11 @@ getPortType portType =
64tuple :: R.Region -> [Raw] -> Raw
64tuple :: R.Region -> [Raw] -> Raw
65tuple region types =
65tuple region types =
66− let name = Var.Raw ("_Tuple" ++ show (length types))
68+ Var.Raw ("_Tuple" ++ show (length types))
68− A.A region (RApp (A.A region (RType name)) types)
70+ A.A region (RApp (A.A region (RType name)) types)
@@ -76,65 +78,68 @@ deepDealias :: Canonical -> Canonical
76deepDealias tipe =
78deepDealias tipe =
77 case tipe of
79 case tipe of
78 Lambda a b ->
80 Lambda a b ->
79− Lambda (deepDealias a) (deepDealias b)
81+ Lambda (deepDealias a) (deepDealias b)
84 Record fields ext ->
86 Record fields ext ->
85− Record (map (second deepDealias) fields) (fmap deepDealias ext)
87+ Record (map (second deepDealias) fields) (fmap deepDealias ext)
87 Aliased _name args tipe' ->
89 Aliased _name args tipe' ->
88− deepDealias (dealias args tipe')
90+ deepDealias (dealias args tipe')
93 App f args ->
95 App f args ->
94− App (deepDealias f) (map deepDealias args)
96+ App (deepDealias f) (map deepDealias args)
97iteratedDealias :: Canonical -> Canonical
99iteratedDealias :: Canonical -> Canonical
98iteratedDealias tipe =
100iteratedDealias tipe =
99 case tipe of
101 case tipe of
100 Aliased _ args realType ->
102 Aliased _ args realType ->
101− iteratedDealias (dealias args realType)
103+ iteratedDealias (dealias args realType)
107dealias :: [(String, Canonical)] -> Aliased Canonical -> Canonical
109dealias :: [(String, Canonical)] -> Aliased Canonical -> Canonical
108dealias args aliasType =
110dealias args aliasType =
109 case aliasType of
111 case aliasType of
110 Holey tipe ->
112 Holey tipe ->
111− dealiasHelp (Map.fromList args) tipe
113+ dealiasHelp (Map.fromList args) tipe
113 Filled tipe ->
115 Filled tipe ->
117dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
119dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
118dealiasHelp typeTable tipe =
120dealiasHelp typeTable tipe =
119− let go = dealiasHelp typeTable in
123+ dealiasHelp typeTable
120− case tipe of
125+ case tipe of
121− Lambda a b ->
126+ Lambda a b ->
122− Lambda (go a) (go b)
127+ Lambda (go a) (go b)
124− Var x ->
129+ Var x ->
125− Map.findWithDefault tipe x typeTable
130+ Map.findWithDefault tipe x typeTable
127− Record fields ext ->
132+ Record fields ext ->
128− Record (map (second go) fields) (fmap go ext)
133+ Record (map (second go) fields) (fmap go ext)
130− Aliased original args t' ->
135+ Aliased original args t' ->
131− Aliased original (map (second go) args) t'
136+ Aliased original (map (second go) args) t'
133− Type _ ->
138+ Type _ ->
136− App f args ->
141+ App f args ->
137− App (go f) (map go args)
142+ App (go f) (map go args)
@@ -145,10 +150,10 @@ collectLambdas :: Canonical -> [Canonical]
145collectLambdas tipe =
150collectLambdas tipe =
146 case tipe of
151 case tipe of
147 Lambda arg result ->
152 Lambda arg result ->
148− arg : collectLambdas result
153+ arg : collectLambdas result
@@ -157,49 +162,49 @@ collectLambdas tipe =
158instance Binary Canonical where
163instance Binary Canonical where
159 put tipe =
164 put tipe =
160− case tipe of
165+ case tipe of
161− Lambda t1 t2 ->
166+ Lambda t1 t2 ->
162− putWord8 0 >> put t1 >> put t2
167+ putWord8 0 >> put t1 >> put t2
164− Var x ->
169+ Var x ->
165− putWord8 1 >> put x
170+ putWord8 1 >> put x
167− Type name ->
172+ Type name ->
168− putWord8 2 >> put name
173+ putWord8 2 >> put name
170− App t1 t2 ->
175+ App t1 t2 ->
171− putWord8 3 >> put t1 >> put t2
176+ putWord8 3 >> put t1 >> put t2
173− Record fs ext ->
178+ Record fs ext ->
174− putWord8 4 >> put fs >> put ext
179+ putWord8 4 >> put fs >> put ext
176− Aliased var args t ->
181+ Aliased var args t ->
177− putWord8 5 >> put var >> put args >> put t
182+ putWord8 5 >> put var >> put args >> put t
180− n <- getWord8
185+ do n <- getWord8
181− case n of
186+ case n of
182− 0 -> Lambda <$> get <*> get
187+ 0 -> Lambda <$> get <*> get
183− 1 -> Var <$> get
188+ 1 -> Var <$> get
184− 2 -> Type <$> get
189+ 2 -> Type <$> get
185− 3 -> App <$> get <*> get
190+ 3 -> App <$> get <*> get
186− 4 -> Record <$> get <*> get
191+ 4 -> Record <$> get <*> get
187− 5 -> Aliased <$> get <*> get <*> get
192+ 5 -> Aliased <$> get <*> get <*> get
188− _ -> error "Error reading a valid type from serialized string"
193+ _ -> error "Error reading a valid type from serialized string"
191instance Binary t => Binary (Aliased t) where
196instance Binary t => Binary (Aliased t) where
192 put aliasType =
197 put aliasType =
193− case aliasType of
198+ case aliasType of
194− Holey tipe ->
199+ Holey tipe ->
195− putWord8 0 >> put tipe
200+ putWord8 0 >> put tipe
197− Filled tipe ->
202+ Filled tipe ->
198− putWord8 1 >> put tipe
203+ putWord8 1 >> put tipe
201− n <- getWord8
206+ do n <- getWord8
202− case n of
207+ case n of
203− 0 -> Holey <$> get
208+ 0 -> Holey <$> get
204− 1 -> Filled <$> get
209+ 1 -> Filled <$> get
205− _ -> error "Error reading a valid type from serialized string"
210+ _ -> error "Error reading a valid type from serialized string"