| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Indexed containers core |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Container.Indexed.Core where |
| 10 |
|
| 11 |
open import Level using (Level; _⊔_; suc) |
| 12 |
open import Data.Product.Base using (Σ; Σ-syntax; _,_; ∃) |
| 13 |
open import Relation.Unary using (Pred) |
| 14 |
|
| 15 |
private variable |
| 16 |
i o c r ℓ ℓ′ : Level |
| 17 |
I : Set i |
| 18 |
O : Set o |
| 19 |
|
| 20 |
------------------------------------------------------------------------ |
| 21 |
-- Definition |
| 22 |
|
| 23 |
infix 5 _◃_/_ |
| 24 |
|
| 25 |
record Container (I : Set i) (O : Set o) c r : Set (i ⊔ o ⊔ suc c ⊔ suc r) where |
| 26 |
constructor _◃_/_ |
| 27 |
field |
| 28 |
Command : (o : O) → Set c |
| 29 |
Response : ∀ {o} → Command o → Set r |
| 30 |
next : ∀ {o} (c : Command o) → Response c → I |
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- The semantics ("extension") of an indexed container. |
| 34 |
|
| 35 |
module _ (C : Container I O c r) (X : Pred I ℓ) where |
| 36 |
open Container C |
| 37 |
|
| 38 |
Subtrees : ∀ o → Command o → Set _ |
| 39 |
Subtrees o c = (r : Response c) → X (next c r) |
| 40 |
|
| 41 |
⟦_⟧ : Pred O _ |
| 42 |
⟦_⟧ o = Σ (Command o) (Subtrees o) |
| 43 |
|
| 44 |
------------------------------------------------------------------------ |
| 45 |
-- All and any |
| 46 |
|
| 47 |
module _ (C : Container I O c r) {X : Pred I ℓ} where |
| 48 |
|
| 49 |
-- All. |
| 50 |
|
| 51 |
□ : Pred (Σ I X) ℓ′ → Pred (Σ O (⟦ C ⟧ X)) _ |
| 52 |
□ P (_ , _ , k) = ∀ r → P (_ , k r) |
| 53 |
|
| 54 |
-- Any. |
| 55 |
|
| 56 |
◇ : Pred (Σ I X) ℓ′ → Pred (Σ O (⟦ C ⟧ X)) _ |
| 57 |
◇ P (_ , _ , k) = ∃ λ r → P (_ , k r) |