| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Streams where all elements satisfy a given property |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --safe --cubical-compatible --guardedness #-} |
| 8 |
|
| 9 |
module Codata.Guarded.Stream.Relation.Unary.All where |
| 10 |
|
| 11 |
open import Codata.Guarded.Stream using (Stream; head; tail) |
| 12 |
open import Data.Product.Base using (_,_; proj₁; proj₂) |
| 13 |
open import Level using (Level) |
| 14 |
open import Relation.Unary using (Pred; _∩_; _⊆_) |
| 15 |
|
| 16 |
private |
| 17 |
variable |
| 18 |
a p ℓ : Level |
| 19 |
A : Set a |
| 20 |
P Q R : Pred A p |
| 21 |
xs : Stream A |
| 22 |
|
| 23 |
infixr 5 _∷_ |
| 24 |
|
| 25 |
record All (P : Pred A ℓ) (as : Stream A) : Set ℓ where |
| 26 |
coinductive |
| 27 |
constructor _∷_ |
| 28 |
field |
| 29 |
head : P (head as) |
| 30 |
tail : All P (tail as) |
| 31 |
|
| 32 |
open All public |
| 33 |
|
| 34 |
map : P ⊆ Q → All P ⊆ All Q |
| 35 |
head (map f xs) = f (head xs) |
| 36 |
tail (map f xs) = map f (tail xs) |
| 37 |
|
| 38 |
zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R |
| 39 |
head (zipWith f (ps , qs)) = f (head ps , head qs) |
| 40 |
tail (zipWith f (ps , qs)) = zipWith f (tail ps , tail qs) |
| 41 |
|
| 42 |
unzipWith : R ⊆ P ∩ Q → All R ⊆ All P ∩ All Q |
| 43 |
head (proj₁ (unzipWith f rs)) = proj₁ (f (head rs)) |
| 44 |
tail (proj₁ (unzipWith f rs)) = proj₁ (unzipWith f (tail rs)) |
| 45 |
head (proj₂ (unzipWith f rs)) = proj₂ (f (head rs)) |
| 46 |
tail (proj₂ (unzipWith f rs)) = proj₂ (unzipWith f (tail rs)) |