@@ -145,7 +145,7 @@ object Syntax {
145
145
def typeShift (d : Int , ty : Ty ): Ty =
146
146
typeShiftAbove(d, 0 , ty)
147
147
148
- def bindingShift (d : Int , bind : Binding ) =
148
+ def bindingShift (d : Int , bind : Binding ): Binding =
149
149
bind match {
150
150
case NameBind => NameBind
151
151
case TyVarBind => TyVarBind
@@ -170,7 +170,7 @@ object Syntax {
170
170
termShift(- 1 , termSubst(0 , termShift(1 , s), t))
171
171
172
172
// [j -> tyS]
173
- private def typeSubst (tyS : Ty , j : Int , tyT : Ty ) = {
173
+ private def typeSubst (tyS : Ty , j : Int , tyT : Ty ): Ty = {
174
174
val onVar = { (c : Int , v : TyVar ) =>
175
175
if (v.i == c) typeShift(c, tyS) else v
176
176
}
@@ -182,20 +182,18 @@ object Syntax {
182
182
typeShift(- 1 , typeSubst(typeShift(1 , tyS), 0 , tyT))
183
183
184
184
// really this is for system F only
185
- private def tytermSubst (tyS : Ty , j : Int , t : Term ) =
185
+ private def tytermSubst (tyS : Ty , j : Int , t : Term ): Term =
186
186
tmMap((c, tv) => tv, (j, tyT) => typeSubst(tyS, j, tyT), j, t)
187
187
188
188
// really this is for system F only
189
189
def tyTermSubstTop (tyS : Ty , t : Term ): Term =
190
190
termShift(- 1 , tytermSubst(typeShift(1 , tyS), 0 , t))
191
-
192
191
}
193
192
194
- import util .Document
195
- import util .Document ._
196
-
197
- // outer means that the term is the top-level term
193
+ // NB: outer means that the term is the top-level term
198
194
object PrettyPrinter {
195
+ import util .Document
196
+ import util .Document ._
199
197
import util .Print ._
200
198
201
199
def ptyType (outer : Boolean , ctx : Context , ty : Ty ): Document =
@@ -206,7 +204,7 @@ object PrettyPrinter {
206
204
def ptyArrowType (outer : Boolean , ctx : Context , tyT : Ty ): Document =
207
205
tyT match {
208
206
case TyArr (tyT1, tyT2) =>
209
- g2(ptyAType(false , ctx, tyT1) :: " ->" :/: ptyArrowType(outer, ctx, tyT2))
207
+ g2(ptyAType(outer = false , ctx, tyT1) :: " ->" :/: ptyArrowType(outer, ctx, tyT2))
210
208
case tyT =>
211
209
ptyAType(outer, ctx, tyT)
212
210
}
@@ -222,10 +220,10 @@ object PrettyPrinter {
222
220
" Bool"
223
221
case TyVariant (fields) =>
224
222
def pf (i : Int , li : String , tyTi : Ty ): Document =
225
- if (i.toString() == li) {
226
- ptyType(false , ctx, tyTi)
223
+ if (i.toString == li) {
224
+ ptyType(outer = false , ctx, tyTi)
227
225
} else {
228
- li :: " :" :/: ptyType(false , ctx, tyTi)
226
+ li :: " :" :/: ptyType(outer = false , ctx, tyTi)
229
227
}
230
228
" <" :: fields.zipWithIndex
231
229
.map { case ((li, tyTi), i) => pf(i + 1 , li, tyTi) }
@@ -237,10 +235,10 @@ object PrettyPrinter {
237
235
" Unit"
238
236
case TyRecord (fields) =>
239
237
def pf (i : Int , li : String , tyTi : Ty ): Document =
240
- if (i.toString() == li) {
241
- ptyType(false , ctx, tyTi)
238
+ if (i.toString == li) {
239
+ ptyType(outer = false , ctx, tyTi)
242
240
} else {
243
- g0(li :: " :" :/: ptyType(false , ctx, tyTi))
241
+ g0(li :: " :" :/: ptyType(outer = false , ctx, tyTi))
244
242
}
245
243
g2(
246
244
" {" :: fields.zipWithIndex
@@ -254,7 +252,8 @@ object PrettyPrinter {
254
252
" (" :: ptyType(outer, ctx, tyT) :: " )"
255
253
}
256
254
257
- def ptyTy (ctx : Context , ty : Ty ) = ptyType(true , ctx, ty)
255
+ def ptyTy (ctx : Context , ty : Ty ): Document =
256
+ ptyType(outer = true , ctx, ty)
258
257
259
258
def ptmTerm (outer : Boolean , ctx : Context , t : Term ): Document =
260
259
t match {
@@ -267,55 +266,55 @@ object PrettyPrinter {
267
266
case TmCase (t, cases) =>
268
267
def pc (li : String , xi : String , ti : Term ): Document = {
269
268
val (ctx1, x1) = ctx.pickFreshName(xi)
270
- " <" :: li :: " =" :: xi :: " >==>" :: ptmTerm(false , ctx1, ti)
269
+ " <" :: li :: " =" :: xi :: " >==>" :: ptmTerm(outer = false , ctx1, ti)
271
270
}
272
271
g2(
273
- " case " :: ptmTerm(false , ctx, t) :: " of" :/:
272
+ " case " :: ptmTerm(outer = false , ctx, t) :: " of" :/:
274
273
cases.map { case (x, y, z) => pc(x, y, z) }.foldRight(empty : Document )(_ :/: " |" :: _)
275
274
)
276
275
case TmAbs (x, tyT1, t2) =>
277
276
val (ctx1, x1) = ctx.pickFreshName(x)
278
- val abs = g0(" lambda" :/: x1 :: " :" :/: ptyType(false , ctx, tyT1) :: " ." )
277
+ val abs = g0(" lambda" :/: x1 :: " :" :/: ptyType(outer = false , ctx, tyT1) :: " ." )
279
278
val body = ptmTerm(outer, ctx1, t2)
280
279
g2(abs :/: body)
281
280
case TmLet (x, t1, t2) =>
282
281
g0(
283
- " let " :: x :: " = " :: ptmTerm(false , ctx, t1) :/: " in" :/: ptmTerm(
284
- false ,
282
+ " let " :: x :: " = " :: ptmTerm(outer = false , ctx, t1) :/: " in" :/: ptmTerm(
283
+ outer = false ,
285
284
ctx.addName(x),
286
285
t2,
287
286
)
288
287
)
289
288
case TmFix (t1) =>
290
- g2(" fix " :: ptmTerm(false , ctx, t1))
289
+ g2(" fix " :: ptmTerm(outer = false , ctx, t1))
291
290
case t => ptmAppTerm(outer, ctx, t)
292
291
293
292
}
294
293
295
294
def ptmAppTerm (outer : Boolean , ctx : Context , t : Term ): Document =
296
295
t match {
297
296
case TmApp (t1, t2) =>
298
- g2(ptmAppTerm(false , ctx, t1) :/: ptmATerm(false , ctx, t2))
297
+ g2(ptmAppTerm(outer = false , ctx, t1) :/: ptmATerm(outer = false , ctx, t2))
299
298
case TmPred (t1) =>
300
- " pred " :: ptmATerm(false , ctx, t1)
299
+ " pred " :: ptmATerm(outer = false , ctx, t1)
301
300
case TmIsZero (t1) =>
302
- " iszero " :: ptmATerm(false , ctx, t1)
301
+ " iszero " :: ptmATerm(outer = false , ctx, t1)
303
302
case t =>
304
303
ptmPathTerm(outer, ctx, t)
305
304
}
306
305
307
306
def ptmPathTerm (outer : Boolean , ctx : Context , t : Term ): Document =
308
307
t match {
309
308
case TmProj (t1, l) =>
310
- ptmATerm(false , ctx, t1) :: " ." :: l
309
+ ptmATerm(outer = false , ctx, t1) :: " ." :: l
311
310
case t1 =>
312
311
ptmAscribeTerm(outer, ctx, t1)
313
312
}
314
313
315
314
def ptmAscribeTerm (outer : Boolean , ctx : Context , t : Term ): Document =
316
315
t match {
317
316
case TmAscribe (t1, tyT1) =>
318
- g0(ptmAppTerm(false , ctx, t1) :/: " as " :: ptyType(false , ctx, tyT1))
317
+ g0(ptmAppTerm(outer = false , ctx, t1) :/: " as " :: ptyType(outer = false , ctx, tyT1))
319
318
case t1 =>
320
319
ptmATerm(outer, ctx, t1)
321
320
}
@@ -327,7 +326,13 @@ object PrettyPrinter {
327
326
case TmFalse =>
328
327
" false"
329
328
case TmTag (l, t, ty) =>
330
- g2(" <" :: l :: " =" :: ptmTerm(false , ctx, t) :: " >" :/: " as " :: ptyType(outer, ctx, ty))
329
+ g2(
330
+ " <" :: l :: " =" :: ptmTerm(outer = false , ctx, t) :: " >" :/: " as " :: ptyType(
331
+ outer,
332
+ ctx,
333
+ ty,
334
+ )
335
+ )
331
336
case TmVar (x, n) =>
332
337
if (ctx.length == n) ctx.index2Name(x)
333
338
else text(" [bad index: " + x + " /" + n + " in {" + ctx.l.mkString(" , " ) + " }]" )
@@ -337,10 +342,10 @@ object PrettyPrinter {
337
342
" unit"
338
343
case TmRecord (fields) =>
339
344
def pf (i : Int , li : String , t : Term ): Document =
340
- if (i.toString() == li) {
341
- ptmTerm(false , ctx, t)
345
+ if (i.toString == li) {
346
+ ptmTerm(outer = false , ctx, t)
342
347
} else {
343
- li :: " =" :: ptmTerm(false , ctx, t)
348
+ li :: " =" :: ptmTerm(outer = false , ctx, t)
344
349
}
345
350
" {" :: fields.zipWithIndex
346
351
.map { case ((li, tyTi), i) => pf(i + 1 , li, tyTi) }
@@ -356,14 +361,15 @@ object PrettyPrinter {
356
361
case TmSucc (s) =>
357
362
pf(i + 1 , s)
358
363
case _ =>
359
- " (succ " :: ptmATerm(false , ctx, t1) :: " )"
364
+ " (succ " :: ptmATerm(outer = false , ctx, t1) :: " )"
360
365
}
361
366
pf(1 , t1)
362
367
case t =>
363
368
" (" :: ptmTerm(outer, ctx, t) :: " )"
364
369
}
365
370
366
- def ptm (ctx : Context , t : Term ) = ptmTerm(true , ctx, t)
371
+ def ptm (ctx : Context , t : Term ): Document =
372
+ ptmTerm(outer = true , ctx, t)
367
373
368
374
def pBinding (ctx : Context , bind : Binding ): Document =
369
375
bind match {
@@ -394,5 +400,4 @@ object PrettyPrinter {
394
400
case TyAbbBind (ty) =>
395
401
" :: *"
396
402
}
397
-
398
403
}
0 commit comments