Newer
Older
-- | The below is an attempt to describe the semantics of gradually
-- | typed languages in a HOAS style.
--
-- | Warning: this might not make any sense without directed type
-- | theory!
open import ErrorDomains
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Data.Product
op : Preorder → Preorder
op X = record
{ X = X.X
; _⊑_ = λ x y → y X.⊑ x
; refl = X.refl
; trans = λ p1 p2 → X.trans p2 p1
}
where module X = Preorder X
opF : ∀ {X Y} → (X ⇨ Y) → op X ⇨ op Y
opF {X}{Y} f = record { f = f.f ; mon = _⇨_.mon f }
where module X = Preorder X
module Y = Preorder Y
module f = _⇨_ f
record FiberPts {X : Preorder}{Y : Preorder} (f : X ⇨ Y) (y : Preorder.X Y) : Set where
field
pt : Preorder.X X
over : _⇨_.f f pt ≡ y
Fiber : {X : Preorder}{Y : Preorder} (f : X ⇨ Y) (y : Preorder.X Y) → Preorder
Fiber {X}{Y} f y = record { X = FiberPts f y
; _⊑_ = λ x x' → FiberPts.pt x ⊑x FiberPts.pt x'
; refl = λ x → X.refl (FiberPts.pt x)
; trans = λ p1 p2 → X.trans p1 p2 }
where module X = Preorder X
_⊑x_ = X._⊑_
module Y = Preorder Y
record fibration {X : Preorder} {Y : Preorder} (f : X ⇨ Y) : Set where
module X = Preorder X
module Y = Preorder Y
_⊑x_ = X._⊑_
_⊑y_ = Y._⊑_
module f = _⇨_ f
field
-- A < B -> tm B -> tm A (downcast)
pull : ∀ (x : X.X) {y : Y.X} → (y ⊑y app f x) → X.X
-- the downcast is a lower bound
-- dncast (A < B) N <= N
pullLB : ∀ {x : X.X} {y : Y.X} → (c : y ⊑y app f x) → pull x c ⊑x x
-- the downcast is the *greatest* lower bound over a type at least as low
-- Given N : B
-- and M' : A' where A' <= A <= B
-- and M' <= N over A' <= A <= B
-- then M' <= dncast (A <= B) N over A' <= A
pullGLB : ∀ {x : X.X} {y : Y.X} {x' : X.X} → (c : y ⊑y app f x) → (app f x' ⊑y y) → (x' ⊑x x) → x' ⊑x pull x c
opfibration : ∀ {X Y} (f : X ⇨ Y) → Set
opfibration f = fibration (opF f)
record GLTC : Set₁ where
field
type : Preorder
module type = Preorder type
_⊑ty_ = type._⊑_
field
term : Preorder
type-of : term ⇨ type
dncasts : fibration type-of
upcasts : opfibration type-of
-- need that the dncast of an upcast is the identity(!)
-- projection : {!!}
module term = Preorder term
module type-of = _⇨_ type-of
_⊑tm_ = term._⊑_
-- dynamic type
field
dyn : type.X
dynT : ∀ A → A ⊑ty dyn
of-ty : type.X → Preorder
of-ty A = Fiber type-of A
-- errors
field
err : ∀ A → Preorder.X (of-ty A)
-- err⊥ : ∀ M →
-- can we define err to be the least element of type dyn which then is then
-- err <= up (M) so dn(err) <= dn(up(M))
-- function types
field
arr : type ⇨ type ⇒ type
arr' : type.X → type.X → type.X
arr' A B = app (app arr A) B
field
lam : ∀ {A B} → (of-ty A ⇒ of-ty B) ⇔ of-ty (arr' A B)
-- can we *prove* that application preserves error, i.e., that (err{A -> B} N = err{B})?
-- doubtful... seems like we need to add it in as an axiom, i.e., that the above is an iso of *pointed* preorders
-- boolean types
field
bool : type.X
-- this doesn't satisfy the UMP because
-- there are terms that are not strict in their input (x |- x)
if : ∀ {A} → product (of-ty A) (of-ty A) ◃ (of-ty bool ⇒ of-ty A)
-- -- terms are more interesting because they are "clocked"
-- term : type → K → Set
-- _||_⊨_⊑₁_ : ∀ {A B : type} → (A ⊑₀ B) → (k : K) → term A k → term B k → ℙ
-- -- reflexivity is "approximation-wise"
-- refl₁ : ∀ {A}{M : ∀ k → term A k} → (k : K) → refl₀ || k ⊨ (M k) ⊑₁ (M k)
-- -- transitivity is only "in the limit"
-- trans₁ : ∀ {A B C}{M : ∀ k → term A k}{N : ∀ k → term B k}{P : ∀ k → term C k}
-- {AB : A ⊑₀ B}{BC : B ⊑₀ C}
-- → (∀ k → AB || k ⊨ (M k) ⊑₁ (N k))
-- → (∀ k → BC || k ⊨ (N k) ⊑₁ (P k))
-- → ∀ k → trans₀ AB BC || k ⊨ (M k) ⊑₁ (P k)
-- -- the above defines a kind of "guarded functor" ty : term -> type
-- -- upcasts/downcasts ask that that functor be an/a opfibration/fibration
-- up : ∀ {A B} → A ⊑₀ B → ∀ k → term A k → term B k
-- dn : ∀ {A B} → A ⊑₀ B → ∀ k → term B k → term A k
-- postulate
-- ▸₁ : Set₁ → Set₁
-- fix : (▸₁ 𝕌 → 𝕌) → 𝕌
-- θ𝕌 : ▸₁ 𝕌 → 𝕌
-- infixl 30 _+_
-- data _+_ (A B : Set) : Set where
-- inl_ : A → A + B
-- inr_ : B → A + B
-- record One : Set where
-- constructor ⟨⟩
-- Two : Set
-- Two = One + One
-- L℧ : Set → Set
-- L℧ X = fix (λ L℧X → One + X + θ𝕌 L℧X)
-- dyn℧ : Set
-- dyn℧ = fix λ dyn℧ → L℧ ((Two + (θ𝕌 dyn℧ → θ𝕌 dyn℧)))
record GTLC-CBV : Set₁ where
field
type : Preorder
valu : Preorder
comp : Preorder
ty-ofv : valu ⇨ type
ty-ofc : comp ⇨ type
module type = Preorder type
val-of-ty : type.X → Preorder
val-of-ty A = Fiber ty-ofv A
comp-of-ty : type.X → Preorder
comp-of-ty A = Fiber ty-ofc A
field
-- not quite right, need the rhs to be some kind of strict morphisms.
-- should probably have a third sort of ev ctxts from A to B
lett : ∀ {A B} → (val-of-ty A ⇒ comp-of-ty B) ⇔ (comp-of-ty A ⇒ comp-of-ty B)
upcasts : opfibration ty-ofv
dncasts : fibration ty-ofc -- problem this doesn't imply that downcasts are linear, maybe we add this as a separate prop?
-- something for projection property
-- dynamic type
dyn : type.X
dyn⊤ : ∀ A → type ⊨ A ⊑ dyn
-- errors...
-- functions
arr : type ⇨ type ⇒ type
arr' : type.X → type.X → type.X
arr' A B = app (app arr A) B
field
lam : ∀ {A B} → (val-of-ty A ⇒ comp-of-ty B) ⇔ val-of-ty (arr' A B)
-- bools
bool : type.X
if : ∀ {A} → product (comp-of-ty A) (comp-of-ty A) ⇔ (val-of-ty bool ⇒ comp-of-ty A)