on master help sign in
cosmetic: modernize whitespace
09e0b44Evan Czaplicki
src/AST/Type.hs+69−64
@@ -63,9 +63,11 @@ getPortType portType =
63
63
64tuple :: R.Region -> [Raw] -> Raw
64tuple :: R.Region -> [Raw] -> Raw
65tuple region types =
65tuple region types =
66+ let
67+ name =
66− let name = Var.Raw ("_Tuple" ++ show (length types))
68+ Var.Raw ("_Tuple" ++ show (length types))
67 in
69 in
68− A.A region (RApp (A.A region (RType name)) types)
70+ A.A region (RApp (A.A region (RType name)) types)
69
71
70
72
71
73
@@ -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)
80
82
81 Var _ ->
83 Var _ ->
82− tipe
84+ tipe
83
85
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)
86
88
87 Aliased _name args tipe' ->
89 Aliased _name args tipe' ->
88− deepDealias (dealias args tipe')
90+ deepDealias (dealias args tipe')
89
91
90 Type _ ->
92 Type _ ->
91− tipe
93+ tipe
92
94
93 App f args ->
95 App f args ->
94− App (deepDealias f) (map deepDealias args)
96+ App (deepDealias f) (map deepDealias args)
95
97
96
98
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)
102
104
103 _ ->
105 _ ->
104− tipe
106+ tipe
105
107
106
108
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
112
114
113 Filled tipe ->
115 Filled tipe ->
114− tipe
116+ tipe
115
117
116
118
117dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
119dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
118dealiasHelp typeTable tipe =
120dealiasHelp typeTable tipe =
121+ let
122+ go =
119− let go = dealiasHelp typeTable in
123+ dealiasHelp typeTable
124+ in
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)
123
128
124− Var x ->
129+ Var x ->
125− Map.findWithDefault tipe x typeTable
130+ Map.findWithDefault tipe x typeTable
126
131
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)
129
134
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'
132
137
133− Type _ ->
138+ Type _ ->
134− tipe
139+ tipe
135
140
136− App f args ->
141+ App f args ->
137− App (go f) (map go args)
142+ App (go f) (map go args)
138
143
139
144
140
145
@@ -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
149
154
150 _ ->
155 _ ->
151− [tipe]
156+ [tipe]
152
157
153
158
154
159
@@ -157,49 +162,49 @@ collectLambdas tipe =
157
162
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
163
168
164− Var x ->
169+ Var x ->
165− putWord8 1 >> put x
170+ putWord8 1 >> put x
166
171
167− Type name ->
172+ Type name ->
168− putWord8 2 >> put name
173+ putWord8 2 >> put name
169
174
170− App t1 t2 ->
175+ App t1 t2 ->
171− putWord8 3 >> put t1 >> put t2
176+ putWord8 3 >> put t1 >> put t2
172
177
173− Record fs ext ->
178+ Record fs ext ->
174− putWord8 4 >> put fs >> put ext
179+ putWord8 4 >> put fs >> put ext
175
180
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
178
183
179− get = do
184+ get =
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"
189
194
190
195
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
196−
201+
197− Filled tipe ->
202+ Filled tipe ->
198− putWord8 1 >> put tipe
203+ putWord8 1 >> put tipe
199−
204+
200− get = do
205+ get =
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"