-
Notifications
You must be signed in to change notification settings - Fork 3
/
Subtyping.agda
99 lines (77 loc) · 2.5 KB
/
Subtyping.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
module Subtyping where
open import Types
-- The subtyping relation(s).
infix 5 _<:₁_
infix 5 _<:₂_
infix 5 _<:₃_
{-
Traditional subtyping, where Dyn (⋆) is at its top.
(The subtyping relations are in the same order as Fig. 3 in the 'Exploring the Design Space' paper. )
-}
data _<:₁_ : Type → Type → Set where
T<:⋆ : ∀ {T}
--------
→ T <:₁ ⋆
<:-B : ∀ {B}
-----------
→ ` B <:₁ ` B
-- Product and sum are monotone with respect to subtyping.
<:-× : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₁ T₁ → S₂ <:₁ T₂
-----------------------
→ S₁ `× S₂ <:₁ T₁ `× T₂
<:-⊎ : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₁ T₁ → S₂ <:₁ T₂
-----------------------
→ S₁ `⊎ S₂ <:₁ T₁ `⊎ T₂
<:-⇒ : ∀ {S₁ S₂ T₁ T₂}
→ T₁ <:₁ S₁ → S₂ <:₁ T₂
-----------------------
→ S₁ ⇒ S₂ <:₁ T₁ ⇒ T₂
{-
Subtyping of WF-1. This is the rarely used one.
-}
data _<:₂_ : Type → Type → Set where
<:-⋆ : ⋆ <:₂ ⋆
<:-B : ∀ {B}
-----------
→ ` B <:₂ ` B
-- Product and sum are monotone with respect to subtyping.
<:-× : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₂ T₁ → S₂ <:₂ T₂
-----------------------
→ S₁ `× S₂ <:₂ T₁ `× T₂
<:-⊎ : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₂ T₁ → S₂ <:₂ T₂
-----------------------
→ S₁ `⊎ S₂ <:₂ T₁ `⊎ T₂
<:-⇒ : ∀ {S₁ S₂ T₁ T₂}
→ T₁ <:₂ S₁ → S₂ <:₂ T₂
-----------------------
→ S₁ ⇒ S₂ <:₂ T₁ ⇒ T₂
{-
Subtyping of WF-2.
This is usually used to characterize the cast safety of UD (which routes through ground types).
-}
data _<:₃_ : Type → Type → Set where
<:-⋆ : ⋆ <:₃ ⋆
<:-B : ∀ {B}
-----------
→ ` B <:₃ ` B
<:-G : ∀ {S G}
→ S <:₃ G → Ground G
--------------------------
→ S <:₃ ⋆
-- Product and sum are monotone with respect to subtyping.
<:-× : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₃ T₁ → S₂ <:₃ T₂
-----------------------
→ S₁ `× S₂ <:₃ T₁ `× T₂
<:-⊎ : ∀ {S₁ S₂ T₁ T₂}
→ S₁ <:₃ T₁ → S₂ <:₃ T₂
-----------------------
→ S₁ `⊎ S₂ <:₃ T₁ `⊎ T₂
<:-⇒ : ∀ {S₁ S₂ T₁ T₂}
→ T₁ <:₃ S₁ → S₂ <:₃ T₂
-----------------------
→ S₁ ⇒ S₂ <:₃ T₁ ⇒ T₂