Codata.stream
stream : 𝕌 → 𝕌
stream = λa. ν (K a × 𝕏)
hd : {a : 𝕌} → stream a → a using (Codata.stream.stream.unfold)
hd = λa t. out t .π₁
tl : {a : 𝕌} → stream a → stream a using (Codata.stream.stream.unfold)
tl = λa t. out t .π₂
cons : {a : 𝕌} → a → stream a → stream a using (Codata.stream.stream.unfold)
cons = λa x s. corec (p : a × stream a. p .π₁, out (p .π₂)) (x, s)
iterate : {a : 𝕌} → (a → a) → a → stream a using (Codata.stream.stream.unfold)
iterate = λa f x. corec (s : a. s, f s) x
hdCons : {a : 𝕌} (x : a) (s : stream a) → hd (cons x s) ≡ x
using (cons.eq, hd.eq, hyp.rw, Codata.stream.eq, Codata.stream.stream.unfold)
hdCons = λa x s. ⋆
hdIterate : {a : 𝕌} (f : a → a) (x : a) → hd (iterate f x) ≡ x using (hd.eq, hyp.rw, iterate.eq)
hdIterate = λa f x. ⋆
hdTlIterate : {a : 𝕌} (f : a → a) (x : a) → hd (tl (iterate f x)) ≡ f x
using (hd.eq, hyp.rw, iterate.eq, tl.eq)
hdTlIterate = λa f x. ⋆
hdTlCons : {a : 𝕌} (x : a) (s : stream a) → hd (tl (cons x s)) ≡ hd s
using (cons.eq, hd.eq, Codata.stream.stream.unfold, tl.eq)
hdTlCons = λa x s. ⋆
map : {a b : 𝕌} → (a → b) → stream a → stream b using (Codata.stream.stream.unfold)
map = λa b f t. corec (s : stream a. f (hd s), tl s) t
hdMap : {a b : 𝕌} (f : a → b) (t : stream a) → hd (map f t) ≡ f (hd t)
using (hd.eq, hyp.rw, map.eq, Codata.stream.eq, Codata.stream.stream.unfold)
hdMap = λa b f t. ⋆
hdTlMap : {a b : 𝕌} (f : a → b) (t : stream a) → hd (tl (map f t)) ≡ f (hd (tl t))
using (hd.eq, hyp.rw, map.eq, Codata.stream.eq, Codata.stream.stream.unfold, tl.eq)
hdTlMap = λa b f t. ⋆
tlCons : {a : 𝕌} (x : a) (s : stream a) → tl (cons x s) ≡ s
using (cons.eq, hyp.rw, Codata.stream.eq, Codata.stream.stream.unfold, tl.eq)
tlCons =
λa x s. coind
u v. ∥(w : stream a)
× (u ≡ corec (p : a × stream a. p .π₁, out (p .π₂)) (out w) ∈ stream a) × (v ≡ w ∈ stream a)∥
⋆ (s, ⋆, ⋆)
u v h. squash-elim h (w. ⋆ (⋆, ⋆ (out (w .π₁) .π₂, ⋆, ⋆)))