@@ -10,6 +10,7 @@ module Codata.Delay.Properties where
10
10
11
11
open import Size
12
12
import Data.Sum.Base as Sum
13
+ import Data.Nat as ℕ
13
14
open import Codata.Thunk using (Thunk; force)
14
15
open import Codata.Conat
15
16
open import Codata.Conat.Bisimilarity as Coℕ using (zero ; suc)
@@ -48,3 +49,59 @@ module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
48
49
map-unfold-fusion f n s with n s
49
50
... | Sum.inj₁ s′ = later λ where .force → map-unfold-fusion f n s′
50
51
... | Sum.inj₂ b = now Eq.refl
52
+
53
+
54
+ ------------------------------------------------------------------------
55
+ -- ⇓
56
+
57
+ ⇓-unique : ∀ {a} {A : Set a} →
58
+ {d : Delay A ∞} →
59
+ (d⇓₁ : d ⇓) → (d⇓₂ : d ⇓) →
60
+ d⇓₁ ≡ d⇓₂
61
+ ⇓-unique {d = now s} (now s) (now s) = Eq.refl
62
+ ⇓-unique {d = later d'} (later l) (later r) =
63
+ Eq.cong later (⇓-unique {d = force d'} l r)
64
+
65
+ module _ {a} {A B : Set a} where
66
+
67
+ bind̅₁ : (d : Delay A ∞) {f : A → Delay B ∞} → bind d f ⇓ → d ⇓
68
+ bind̅₁ (now s) _ = now s
69
+ bind̅₁ (later s) (later x) =
70
+ later (bind̅₁ (force s) x)
71
+
72
+ bind̅₂ : (d : Delay A ∞) {f : A → Delay B ∞} →
73
+ (bind⇓ : bind d f ⇓) →
74
+ f (extract (bind̅₁ d bind⇓)) ⇓
75
+ bind̅₂ (now s) foo = foo
76
+ bind̅₂ (later s) {f} (later foo) =
77
+ bind̅₂ (force s) foo
78
+
79
+ -- The extracted value of a bind is equivalent to the extracted value of its
80
+ -- second element
81
+ extract-bind-⇓ : {d : Delay A Size.∞} → {f : A → Delay B Size.∞} →
82
+ (d⇓ : d ⇓) → (f⇓ : f (extract d⇓) ⇓) →
83
+ extract (bind-⇓ d⇓ {f} f⇓) ≡ extract f⇓
84
+ extract-bind-⇓ (now a) f⇓ = Eq.refl
85
+ extract-bind-⇓ (later t) f⇓ = extract-bind-⇓ t f⇓
86
+
87
+ -- If the right element of a bind returns a certain value so does the entire
88
+ -- bind
89
+ extract-bind̅₂-bind⇓ :
90
+ (d : Delay A ∞) {f : A → Delay B ∞} →
91
+ (bind⇓ : bind d f ⇓) →
92
+ extract (bind̅₂ d bind⇓) ≡ extract bind⇓
93
+ extract-bind̅₂-bind⇓ (now s) bind⇓ = Eq.refl
94
+ extract-bind̅₂-bind⇓ (later s) (later bind⇓) =
95
+ extract-bind̅₂-bind⇓ (force s) bind⇓
96
+
97
+ -- Proof that the length of a bind-⇓ is equal to the sum of the length of its
98
+ -- components.
99
+ bind⇓-length :
100
+ {d : Delay A ∞} {f : A → Delay B ∞} →
101
+ (bind⇓ : bind d f ⇓) →
102
+ (d⇓ : d ⇓) → (f⇓ : f (extract d⇓) ⇓) →
103
+ toℕ (length-⇓ bind⇓) ≡ toℕ (length-⇓ d⇓) ℕ.+ toℕ (length-⇓ f⇓)
104
+ bind⇓-length {f = f} bind⇓ d⇓@(now s') f⇓ =
105
+ Eq.cong (toℕ ∘ length-⇓) (⇓-unique bind⇓ f⇓)
106
+ bind⇓-length {d = d@(later dt)} {f = f} bind⇓@(later bind'⇓) d⇓@(later r) f⇓ =
107
+ Eq.cong ℕ.suc (bind⇓-length bind'⇓ r f⇓)
0 commit comments