@@ -37,7 +37,7 @@ data Type
3737 = Lambda Type Type
3838 | Var N.Name
3939 | Type N.Name [Type]
40− | Record [(N.Name, Type)] (Maybe Type)
40+ | Record [(N.Name, Type)] (Maybe N.Name)
4141 | Unit
4242 | Tuple Type Type [Type]
4343
@@ -127,29 +127,31 @@ toDoc context tipe =
127127 _ ->
128128 application
129129
130− Record _ _ ->
131− case flattenRecord tipe of
132− ([], Nothing) ->
133− P.text "{}"
130+ Record [] Nothing ->
131+ "{}"
134132
135− (fields, Nothing) ->
136− P.sep
137− [ P.cat (zipWith (<+>) ("{" : repeat ",") (map prettyField fields))
138− , "}"
139− ]
133+ Record fields ext ->
134+ case ext of
135+ Nothing ->
136+ P.sep
137+ [ P.cat (zipWith (<+>) ("{" : repeat ",") (map entryToDoc fields))
138+ , "}"
139+ ]
140140
141− (fields, Just x) ->
142− P.hang
143− ("{" <+> P.text (N.toString x) <+> "|")
144− 4
145− (P.sep
146− [ P.sep (P.punctuate "," (map prettyField fields))
147− , "}"
148− ]
149− )
150− where
151− prettyField (field, fieldType) =
152− P.text (N.toString field) <+> ":" <+> toDoc None fieldType
141+ Just x ->
142+ P.hang
143+ ("{" <+> P.text (N.toString x) <+> "|")
144+ 4
145+ (P.sep
146+ [ P.sep (P.punctuate "," (map entryToDoc fields))
147+ , "}"
148+ ]
149+ )
150+
151+
152+entryToDoc :: (N.Name, Type) -> P.Doc
153+entryToDoc (field, fieldType) =
154+ P.text (N.toString field) <+> ":" <+> toDoc None fieldType
153155
154156
155157collectLambdas :: Type -> [Type]
@@ -159,24 +161,6 @@ collectLambdas tipe =
159161 _ -> [tipe]
160162
161163
162−flattenRecord :: Type -> ( [(N.Name, Type)], Maybe N.Name )
163−flattenRecord tipe =
164− case tipe of
165− Var x ->
166− ([], Just x)
167−
168− Record fields Nothing ->
169− (fields, Nothing)
170−
171− Record fields (Just ext) ->
172− let (fields',ext') = flattenRecord ext
173− in
174− (fields' ++ fields, ext')
175−
176− _ ->
177− error "Trying to flatten ill-formed record."
178−
179−
180164
181165-- JSON for TYPE
182166
@@ -225,7 +209,7 @@ fromRawType (A.At _ astType) =
225209 let fromField (A.At _ field, tipe) = (field, fromRawType tipe) in
226210 Record
227211 (map fromField fields)
228− (fmap fromRawType ext)
212+ (fmap A.toValue ext)
229213
230214
231215