-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemmas-matching.agda
72 lines (63 loc) · 2.37 KB
/
lemmas-matching.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
open import Prelude
open import dynamics-core
module lemmas-matching where
-- arrow matching produces unique answers
▸arr-unicity : ∀{τ τ2 τ3} →
τ ▸arr τ2 →
τ ▸arr τ3 →
τ2 == τ3
▸arr-unicity MAHole MAHole = refl
▸arr-unicity MAArr MAArr = refl
-- only consistent types arrow match
▸arr-consist : ∀{τ1 τ2} →
τ1 ▸arr τ2 →
(τ1 ~ τ2)
▸arr-consist MAHole = TCHole2
▸arr-consist MAArr = TCRefl
-- if an arrow matches, then it's consistent with the
-- least restrictive function type
▸arr-consist-hole : ∀{t t'} →
t ▸arr t' →
t ~ (⦇-⦈ ==> ⦇-⦈)
▸arr-consist-hole MAHole = TCHole2
▸arr-consist-hole MAArr = TCArr TCHole1 TCHole1
-- sum matching produces unique answers
▸sum-unicity : ∀{τ τ2 τ3} →
τ ▸sum τ2 →
τ ▸sum τ3 →
τ2 == τ3
▸sum-unicity MSHole MSHole = refl
▸sum-unicity MSSum MSSum = refl
-- only consistent types sum match
▸sum-consist : ∀{τ1 τ2} →
τ1 ▸sum τ2 →
(τ1 ~ τ2)
▸sum-consist MSHole = TCHole2
▸sum-consist MSSum = TCRefl
-- if a sum matches, then it's consistent with the
-- least restrictive function type
▸sum-consist-hole : ∀{t t'} →
t ▸sum t' →
t ~ (⦇-⦈ ⊕ ⦇-⦈)
▸sum-consist-hole MSHole = TCHole2
▸sum-consist-hole MSSum = TCSum TCHole1 TCHole1
-- product matching produces unique answers
▸prod-unicity : ∀{τ τ2 τ3} →
τ ▸prod τ2 →
τ ▸prod τ3 →
τ2 == τ3
▸prod-unicity MPHole MPHole = refl
▸prod-unicity MPProd MPProd = refl
-- only consistent types product match
▸prod-consist : ∀{τ1 τ2} →
τ1 ▸prod τ2 →
(τ1 ~ τ2)
▸prod-consist MPHole = TCHole2
▸prod-consist MPProd = TCRefl
-- if a sum matches, then it's consistent with the
-- least restrictive function type
▸prod-consist-hole : ∀{t t'} →
t ▸prod t' →
t ~ (⦇-⦈ ⊠ ⦇-⦈)
▸prod-consist-hole MPHole = TCHole2
▸prod-consist-hole MPProd = TCProd TCHole1 TCHole1