Skip to content

Commit 86bb04a

Browse files
committed
Changed syntax for Has_type.
1 parent 2d44378 commit 86bb04a

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/Types.lidr

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -302,42 +302,42 @@ is always empty.
302302
\newline
303303
\]
304304

305-
> syntax "|-" [p] "." [q] = Has_type p q
305+
> syntax "|-" [p] ":" [q] "."= Has_type p q
306306

307307
> data Has_type : Tm -> Ty -> Type where
308-
> T_True : |- Ttrue . TBool
309-
> T_False : |- Tfalse . TBool
308+
> T_True : |- Ttrue : TBool .
309+
> T_False : |- Tfalse : TBool .
310310
> T_If : {t1, t2, t3: Tm} -> {T: Ty} ->
311-
> Has_type t1 TBool ->
312-
> Has_type t2 T ->
313-
> Has_type t3 T ->
314-
> |- (Tif t1 t2 t3) . T
315-
> T_Zero : |- Tzero . TNat
311+
> |- t1 : TBool . ->
312+
> |- t2 : T . ->
313+
> |- t3 : T . ->
314+
> |- (Tif t1 t2 t3) : T .
315+
> T_Zero : |- Tzero : TNat .
316316
> T_Succ : {t1 : Tm} ->
317-
> Has_type t1 TNat ->
318-
> |- (Tsucc t1) . TNat
317+
> |- t1 : TNat . ->
318+
> |- (Tsucc t1) : TNat .
319319
> T_Pred : {t1 : Tm} ->
320-
> Has_type t1 TNat ->
321-
> |- (Tpred t1) . TNat
320+
> |- t1 : TNat . ->
321+
> |- (Tpred t1) : TNat .
322322
> T_Iszero : {t1 : Tm} ->
323-
> Has_type t1 TNat ->
324-
> |- (Tiszero t1) . TBool
323+
> |- t1 : TNat . ->
324+
> |- (Tiszero t1) : TBool .
325325

326-
> has_type_1 : |- (Tif Tfalse Tzero (Tsucc Tzero)) . TNat
326+
> has_type_1 : |- (Tif Tfalse Tzero (Tsucc Tzero)) : TNat .
327327
> has_type_1 = T_If (T_False) (T_Zero) (T_Succ T_Zero)
328328

329329
It's important to realize that the typing relation is a
330330
_conservative_ (or _static_) approximation: it does not consider
331331
what happens when the term is reduced -- in particular, it does
332332
not calculate the type of its normal form.
333333

334-
> has_type_not : Not (Has_type (Tif Tfalse Tzero Ttrue) TBool)
334+
> has_type_not : Not ( |- (Tif Tfalse Tzero Ttrue) : TBool . )
335335
> has_type_not (T_If (T_False) (T_Zero) (T_True)) impossible
336336

337337
==== Exercise: 1 star, optional (succ_hastype_nat__hastype_nat)
338338

339339
> succ_hastype_nat__hastype_nat : {t : Tm} ->
340-
> Has_type (Tsucc t) TNat -> |- t . TNat
340+
> |- (Tsucc t) : TNat . -> |- t : TNat .
341341
> succ_hastype_nat__hastype_nat = ?succ_hastype_nat__hastype_nat_rhs
342342

343343
$\square$
@@ -348,21 +348,21 @@ The following two lemmas capture the fundamental property that the
348348
definitions of boolean and numeric values agree with the typing
349349
relation.
350350

351-
> bool_canonical : {t: Tm} -> Has_type t TBool -> Value t -> Bvalue t
351+
> bool_canonical : {t: Tm} -> |- t : TBool . -> Value t -> Bvalue t
352352
> bool_canonical {t} ht v =
353353
> case v of
354354
> V_bool b => b
355355
> V_nat n => void (lemma n ht)
356-
> where lemma : {t:Tm} -> Nvalue t -> Not (Has_type t TBool)
356+
> where lemma : {t:Tm} -> Nvalue t -> Not ( |- t : TBool . )
357357
> lemma {t=Tzero} n T_Zero impossible
358358
> lemma {t=Tsucc n'} n (T_Succ n') impossible
359359

360-
> nat_canonical : {t: Tm} -> Has_type t TNat -> Value t -> Nvalue t
360+
> nat_canonical : {t: Tm} -> |- t : TNat . -> Value t -> Nvalue t
361361
> nat_canonical {t} ht v =
362362
> case v of
363363
> V_nat n => n
364364
> V_bool b => void (lemma b ht)
365-
> where lemma : {t:Tm} -> Bvalue t -> Not (Has_type t TNat)
365+
> where lemma : {t:Tm} -> Bvalue t -> Not ( |- t : TNat . )
366366
> lemma {t=Ttrue} n T_True impossible
367367
> lemma {t=Tfalse} n T_False impossible
368368

@@ -373,7 +373,7 @@ that well-typed normal forms are not stuck -- or conversely, if a
373373
term is well typed, then either it is a value or it can take at
374374
least one step. We call this _progress_.
375375

376-
> progress : {t: Tm} -> {ty: Ty} -> Has_type t ty -> Either (Value t) (t' ** t ->> t')
376+
> progress : {t: Tm} -> {ty: Ty} -> |- t : ty . -> Either (Value t) (t' ** t ->> t')
377377

378378
==== Exercise: 3 stars (finish_progress)
379379

@@ -434,7 +434,7 @@ The second critical property of typing is that, when a well-typed
434434
term takes a step, the result is also a well-typed term.
435435

436436
> preservation : {t, t': Tm} -> {T: Ty} ->
437-
> Has_type t T -> t ->> t' -> |- t' . T
437+
> |- t : T . -> t ->> t' -> |- t' : T .
438438

439439
==== Exercise: 2 stars (finish_preservation)
440440

@@ -500,17 +500,17 @@ each one is doing. The set-up for this proof is similar, but
500500
not exactly the same.
501501

502502
> preservation' : {t, t': Tm} -> {T: Ty} ->
503-
> Has_type t T -> t ->> t' -> |- t' . T
503+
> |- t : T . -> t ->> t' -> |- t' : T .
504504
> preservation' h1 h2 = ?preservation'_rhs
505505

506+
$\square$
507+
506508
The preservation theorem is often called _subject reduction_,
507509
because it tells us what happens when the "subject" of the typing
508510
relation is reduced. This terminology comes from thinking of
509511
typing statements as sentences, where the term is the subject and
510512
the type is the predicate.
511513

512-
$\square$
513-
514514
=== Type Soundness
515515

516516
Putting progress and preservation together, we see that a
@@ -525,7 +525,7 @@ well-typed term can never reach a stuck state.
525525
> multistep = Multi Step
526526

527527
> soundness : {t, t': Tm} -> {T: Ty} ->
528-
> Has_type t T ->
528+
> |- t : T . ->
529529
> t ->>* t' ->
530530
> Not (stuck t')
531531
> soundness ht Multi_refl (sl,sr) =

0 commit comments

Comments
 (0)