2
Stream transducers have been described in:
4
N. Ghani, P. Hancock, and D. Pattinson,
5
Continuous functions on final coalgebras.
6
In Proc. CMCS 2006, Electr. Notes in Theoret. Comp. Sci., 2006.
8
They have been modelled by mixed equi-(co)inductive sized types in
11
Mixed Inductive/Coinductive Types and Strong Normalization.
12
In APLAS 2007, LNCS 4807.
14
Here we model them by mutual data/codata and mixed recursion/corecursion.
15
Cf. examples/Termination/StreamProc.agda
18
module StreamEating where
20
open import Common.Coinduction
23
data Stream (A : Set) : Set where
24
_∷_ : (x : A) (xs : ∞ (Stream A)) → Stream A
27
data SP (A B : Set) : Set where
28
get : (f : A → SP A B) → SP A B
29
put : (b : B) (sp : ∞ (SP A B)) → SP A B
31
eat : ∀ {A B} → SP A B → Stream A → Stream B
32
eat (get f) (a ∷ as) = eat (f a) (♭ as)
33
eat (put b sp) as = b ∷ ♯ eat (♭ sp) as
35
_∘_ : ∀ {A B C} → SP B C → SP A B → SP A C
36
get f₁ ∘ put x sp₂ = f₁ x ∘ ♭ sp₂
37
put x sp₁ ∘ sp₂ = put x (♯ (♭ sp₁ ∘ sp₂))
38
sp₁ ∘ get f₂ = get (λ x → sp₁ ∘ f₂ x)