{-# OPTIONS --postfix-projections #-}
module StreamProcessors where
open import Prelude
record Str (i : Size) (A : Set) : Set where
coinductive
field force : ∀{j : Size< i} → A × Str j A
open Str
hd : ∀{i A} → Str (↑ i) A → A
hd s = s .force .fst
tl : ∀{i A} → Str (↑ i) A → Str i A
tl s = s .force .snd
data SPμ (i : Size) (A B X : Set) : Set where
get : ∀{j : Size< i} (f : A → SPμ j A B X) → SPμ i A B X
put : B × X → SPμ i A B X
record SPν (i : Size) (A B : Set) : Set where
coinductive
field out : ∀{j : Size< i} → SPμ ∞ A B (SPν j A B)
open SPν
mutual
runμ : ∀{i j A B} → SPμ j A B (SPν i A B) → Str ∞ A → B × Str i B
runμ (get f) vs = runμ (f (hd vs)) (tl vs)
runμ (put (w , sp)) vs = w , runν sp vs
runν : ∀{i A B} → SPν i A B → Str ∞ A → Str i B
runν sp vs .force = runμ (sp .out) vs