|
| 1 | +base : type. |
| 2 | +arb : base. |
| 3 | + |
| 4 | +ty+ : type. |
| 5 | +t1 : ty+. |
| 6 | +tprod : ty+ -> ty+ -> ty+. |
| 7 | +tsum : ty+ -> ty+ -> ty+. |
| 8 | +tbase : base -> ty+. |
| 9 | + |
| 10 | +base_value : base -> type. |
| 11 | +bv : base_value arb. |
| 12 | + |
| 13 | +% values: inhabitants of positive types |
| 14 | +value : ty+ -> type. |
| 15 | +unit : value t1. |
| 16 | +pair : value A -> value B -> value (tprod A B). |
| 17 | +inl : value A -> value (tsum A B). |
| 18 | +inr : value B -> value (tsum A B). |
| 19 | +vbase : base_value P -> value (tbase P). |
| 20 | + |
| 21 | +% analogous to left rules of sequent calculus |
| 22 | +trans : ty+ -> ty+ -> type. |
| 23 | +ignore : value C -> trans t1 C. % could be "trans A C" in general |
| 24 | +split : (value A -> trans B C) -> trans (tprod A B) C. |
| 25 | +case : trans A C -> trans B C -> trans (tsum A B) C. |
| 26 | +% case : (value A -> value C) -> (value B -> value C) |
| 27 | +% -> trans (tsum A B) C. |
| 28 | +id : trans A A. |
| 29 | +seq : trans A B -> trans B C -> trans A C. |
| 30 | +bind : (value A -> value B) -> trans A B. |
| 31 | + |
| 32 | + |
| 33 | +% eval |
| 34 | +eval : value T -> trans T C -> value C -> type. |
| 35 | +%mode eval +Value +Trans -Value2. |
| 36 | +eval/split |
| 37 | + : eval (pair V1 V2) (split Cont) V |
| 38 | + <- eval V2 (Cont V1) V. |
| 39 | +eval/ignore |
| 40 | + : eval unit (ignore V) V. |
| 41 | +eval/case/inl |
| 42 | + : eval (inl V1) (case T1 T2) V |
| 43 | + <- eval V1 T1 V. |
| 44 | +eval/case/inr |
| 45 | + : eval (inr V2) (case T1 T2) V |
| 46 | + <- eval V2 T2 V. |
| 47 | +eval/bind |
| 48 | + : eval V (bind ([x] V' x)) (V' V). |
| 49 | + |
| 50 | + |
| 51 | +a : base. |
| 52 | +b : base. |
| 53 | +c : base. |
| 54 | + |
| 55 | +a_val : base_value a. |
| 56 | +b_val : base_value b. |
| 57 | +c_val : base_value c. |
| 58 | + |
| 59 | +example1 : trans |
| 60 | + (tprod (tbase a) (tsum (tbase b) (tbase c))) |
| 61 | + (tsum (tprod (tbase a) (tbase b)) (tbase c)). |
| 62 | +example1 = split ([x] case (bind [z] inl (pair x z)) (bind [w] inr w)). |
| 63 | +example1_in = pair (vbase a_val) (inl (vbase b_val)). |
| 64 | + |
| 65 | +%solve example_eval : eval example1_in example1 Out. |
| 66 | + |
| 67 | + |
| 68 | + |
0 commit comments