| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Values for AVL trees |
| 5 |
-- Values must respect the underlying equivalence on keys |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Relation.Binary.Bundles using (Setoid) |
| 11 |
open import Relation.Binary.Definitions using (_Respects_) |
| 12 |
|
| 13 |
module Data.Tree.AVL.Value {a ℓ} (S : Setoid a ℓ) where |
| 14 |
|
| 15 |
open import Data.Product.Base using (Σ; _,_) |
| 16 |
open import Level using (suc; _⊔_) |
| 17 |
import Function.Base as F |
| 18 |
open Setoid S renaming (Carrier to Key) |
| 19 |
|
| 20 |
------------------------------------------------------------------------ |
| 21 |
-- A Value |
| 22 |
|
| 23 |
record Value v : Set (a ⊔ ℓ ⊔ suc v) where |
| 24 |
constructor MkValue |
| 25 |
field |
| 26 |
family : Key → Set v |
| 27 |
respects : family Respects _≈_ |
| 28 |
|
| 29 |
------------------------------------------------------------------------ |
| 30 |
-- A Key together with its value |
| 31 |
|
| 32 |
record K&_ {v} (V : Value v) : Set (a ⊔ v) where |
| 33 |
constructor _,_ |
| 34 |
field |
| 35 |
key : Key |
| 36 |
value : Value.family V key |
| 37 |
infixr 4 _,_ |
| 38 |
open K&_ public |
| 39 |
|
| 40 |
module _ {v} {V : Value v} where |
| 41 |
|
| 42 |
toPair : K& V → Σ Key (Value.family V) |
| 43 |
toPair (k , v) = k , v |
| 44 |
|
| 45 |
fromPair : Σ Key (Value.family V) → K& V |
| 46 |
fromPair (k , v) = k , v |
| 47 |
|
| 48 |
------------------------------------------------------------------------ |
| 49 |
-- The constant family of values |
| 50 |
|
| 51 |
-- The function `const` is defined using copatterns to prevent eager |
| 52 |
-- unfolding of the function in goal types. |
| 53 |
const : ∀ {v} → Set v → Value v |
| 54 |
Value.family (const V) = F.const V |
| 55 |
Value.respects (const V) = F.const F.id |