Debian Codegraph @

src/Codata/Guarded/Stream/Relation/Unary/Any.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Streams where at least one element satisfies a given property
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --safe --cubical-compatible --guardedness #-}
8
9 module Codata.Guarded.Stream.Relation.Unary.Any where
10
11 open import Codata.Guarded.Stream as Stream using (Stream)
12 open import Data.Nat.Base hiding (_⊔_)
13 open import Level hiding (zero; suc)
14 open import Relation.Nullary.Negation.Core using (¬_; contradiction)
15 open import Relation.Unary using (Pred; _⊆_)
16
17 private
18 variable
19 a p q : Level
20 A : Set a
21 P Q : Pred A p
22 xs : Stream A
23
24 data Any {A : Set a} (P : Pred A p) : Stream A → Set (a ⊔ p) where
25 here : ∀ {xs} → P (Stream.head xs) → Any P xs
26 there : ∀ {xs} → Any P (Stream.tail xs) → Any P xs
27
28 head : ¬ Any P (Stream.tail xs) → Any P xs → P (Stream.head xs)
29 head ¬t (here h) = h
30 head ¬t (there t) = contradiction t ¬t
31
32 tail : ¬ P (Stream.head xs) → Any P xs → Any P (Stream.tail xs)
33 tail ¬h (here h) = contradiction h ¬h
34 tail ¬h (there t) = t
35
36 map : P ⊆ Q → Any P ⊆ Any Q
37 map g (here px ) = here (g px)
38 map g (there pxs) = there (map g pxs)
39
40 index : Any P xs → ℕ
41 index (here px ) = zero
42 index (there pxs) = suc (index pxs)
43
44 lookup : {P : Pred A p} → Any P xs → A
45 lookup {xs = xs} p = Stream.lookup xs (index p)
46