-
Notifications
You must be signed in to change notification settings - Fork 3
/
ParamCCPrecisionABT.agda
156 lines (129 loc) · 4.96 KB
/
ParamCCPrecisionABT.agda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
open import Data.List
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl)
open import Data.Product
using (_×_; proj₁; proj₂; ∃; ∃-syntax)
renaming (_,_ to ⟨_,_⟩)
open import Types
open import Labels
open import PreCastStructure
open import Syntax
module ParamCCPrecisionABT (precast : PreCastStruct) where
open PreCastStruct precast
open import ParamCastCalculusABT precast
{- The precision relation for the cast calculus. -}
infix 4 _,_⊢_⊑_
data _,_⊢_⊑_ : ∀ (Γ Γ′ : List Type) → (M M′ : Term) → Set where
⊑-$ : ∀ {Γ Γ′ A} {r : rep A} {p : Prim A}
--------------------------------------
→ Γ , Γ′ ⊢ $ r # p ⊑ $ r # p
⊑-` : ∀ {Γ Γ′} {x : Var}
---------------------
→ Γ , Γ′ ⊢ ` x ⊑ ` x
⊑-ƛ : ∀ {Γ Γ′ A A′} {N N′ : Term}
→ A ⊑ A′
→ A ∷ Γ , A′ ∷ Γ′ ⊢ N ⊑ N′
------------------------------
→ Γ , Γ′ ⊢ ƛ A ˙ N ⊑ ƛ A′ ˙ N′
⊑-· : ∀ {Γ Γ′} {L L′ M M′ : Term}
→ Γ , Γ′ ⊢ L ⊑ L′
→ Γ , Γ′ ⊢ M ⊑ M′
--------------------------
→ Γ , Γ′ ⊢ L · M ⊑ L′ · M′
⊑-if : ∀ {Γ Γ′} {L L′ M M′ N N′ : Term}
→ Γ , Γ′ ⊢ L ⊑ L′
→ Γ , Γ′ ⊢ M ⊑ M′
→ Γ , Γ′ ⊢ N ⊑ N′
----------------------------------------
→ Γ , Γ′ ⊢ if L then M else N endif ⊑
if L′ then M′ else N′ endif
⊑-cons : ∀ {Γ Γ′} {M M′ N N′ : Term}
→ Γ , Γ′ ⊢ M ⊑ M′
→ Γ , Γ′ ⊢ N ⊑ N′
----------------------------------
→ Γ , Γ′ ⊢ ⟦ M , N ⟧ ⊑ ⟦ M′ , N′ ⟧
⊑-fst : ∀ {Γ Γ′} {M M′ : Term}
→ Γ , Γ′ ⊢ M ⊑ M′
-------------------------
→ Γ , Γ′ ⊢ fst M ⊑ fst M′
⊑-snd : ∀ {Γ Γ′} {M M′ : Term}
→ Γ , Γ′ ⊢ M ⊑ M′
-------------------------
→ Γ , Γ′ ⊢ snd M ⊑ snd M′
⊑-inl : ∀ {Γ Γ′ B B′} {M M′ : Term}
→ B ⊑ B′
→ Γ , Γ′ ⊢ M ⊑ M′
------------------------------------------
→ Γ , Γ′ ⊢ inl M other B ⊑ inl M′ other B′
⊑-inr : ∀ {Γ Γ′ A A′} {M M′ : Term}
→ A ⊑ A′
→ Γ , Γ′ ⊢ M ⊑ M′
------------------------------------------
→ Γ , Γ′ ⊢ inr M other A ⊑ inr M′ other A′
⊑-case : ∀ {Γ Γ′ A A′ B B′} {L L′ M M′ N N′ : Term}
→ Γ , Γ′ ⊢ L ⊑ L′
→ A ⊑ A′
→ B ⊑ B′
→ A ∷ Γ , A′ ∷ Γ′ ⊢ M ⊑ M′
→ B ∷ Γ , B′ ∷ Γ′ ⊢ N ⊑ N′
------------------------------------------
→ Γ , Γ′ ⊢ case L of A ⇒ M ∣ B ⇒ N ⊑
case L′ of A′ ⇒ M′ ∣ B′ ⇒ N′
⊑-cast : ∀ {Γ Γ′ A A′ B B′} {M M′ : Term}
{c : Cast (A ⇒ B)} {c′ : Cast (A′ ⇒ B′)}
→ A ⊑ A′
→ B ⊑ B′
→ Γ , Γ′ ⊢ M ⊑ M′
------------------------------
→ Γ , Γ′ ⊢ M ⟨ c ⟩ ⊑ M′ ⟨ c′ ⟩
⊑-castl : ∀ {Γ Γ′ A A′ B} {M M′ : Term}
{c : Cast (A ⇒ B)}
→ A ⊑ A′
→ B ⊑ A′
→ Γ′ ⊢ M′ ⦂ A′
→ Γ , Γ′ ⊢ M ⊑ M′
-----------------------
→ Γ , Γ′ ⊢ M ⟨ c ⟩ ⊑ M′
⊑-castr : ∀ {Γ Γ′ A A′ B′} {M M′ : Term}
{c′ : Cast (A′ ⇒ B′)}
→ A ⊑ A′
→ A ⊑ B′
→ Γ ⊢ M ⦂ A
→ Γ , Γ′ ⊢ M ⊑ M′
------------------------
→ Γ , Γ′ ⊢ M ⊑ M′ ⟨ c′ ⟩
⊑-wrap : ∀ {Γ Γ′ A A′ B B′} {M M′ : Term}
{c : Cast (A ⇒ B)} {c′ : Cast (A′ ⇒ B′)}
{i : Inert c} {i′ : Inert c′}
→ A ⊑ A′
→ B ⊑ B′
→ Γ , Γ′ ⊢ M ⊑ M′
→ (B ≡ ⋆ → B′ ≡ ⋆)
-----------------------------------------
→ Γ , Γ′ ⊢ M ⟨ c ₍ i ₎⟩ ⊑ M′ ⟨ c′ ₍ i′ ₎⟩
⊑-wrapl : ∀ {Γ Γ′ A A′ B} {M M′ : Term}
{c : Cast (A ⇒ B)} {i : Inert c}
→ A ⊑ A′
→ B ⊑ A′
→ Γ′ ⊢ M′ ⦂ A′
→ Γ , Γ′ ⊢ M ⊑ M′
---------------------------
→ Γ , Γ′ ⊢ M ⟨ c ₍ i ₎⟩ ⊑ M′
⊑-wrapr : ∀ {Γ Γ′ A A′ B′} {M M′ : Term}
{c′ : Cast (A′ ⇒ B′)} {i′ : Inert c′}
→ A ⊑ A′
→ A ⊑ B′
→ Γ ⊢ M ⦂ A
→ Γ , Γ′ ⊢ M ⊑ M′
→ A ≢ ⋆
-----------------------------
→ Γ , Γ′ ⊢ M ⊑ M′ ⟨ c′ ₍ i′ ₎⟩
⊑-blame : ∀ {Γ Γ′ A A′} {M : Term} {ℓ}
→ Γ ⊢ M ⦂ A
→ A ⊑ A′
-------------------------------
→ Γ , Γ′ ⊢ M ⊑ blame A′ ℓ
-- Example(s):
private
_ : [] , [] ⊢ ƛ ⋆ ˙ (` 0) ⊑ ƛ (` Nat) ˙ (` 0)
_ = ⊑-ƛ unk⊑ ⊑-`