I am not confident enough to try proving properties about the AVL tree that is there, so I want to try something simpler. I could implement it on my own, but do not want to spend time doing that if it is already hiding in the library somewhere.
Asked
Active
Viewed 64 times
0
-
2FYI, I think it's called an "association list" rather than an "associative list". – Jesper Nov 05 '19 at 11:14
1 Answers
1
You could use a list of pairs and the notion of membership can then be encoded via Any
.
Bits of a very basic library:
open import Data.List.Base using (List)
open import Data.List.Relation.Unary.Any
open import Data.Maybe
open import Data.Product
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
AssocList : Set → Set → Set
AssocList A B = List (A × B)
private
variable
A B : Set
_∈_ : A → AssocList A B → Set
a ∈ abs = Any ((a ≡_) ∘ proj₁) abs
module Decidable {A : Set} (_≟_ : Decidable {A = A} _≡_) where
_∈?_ : Decidable (_∈_ {A} {B})
a ∈? abs = any ((a ≟_) ∘ proj₁) abs
_‼_ : (abs : AssocList A B) (a : A) → Maybe B
abs ‼ a with a ∈? abs
... | yes p = just (proj₂ (lookup p))
... | no ¬p = nothing

gallais
- 11,823
- 2
- 30
- 63
-
Yeah, doing it like this was my intention unless it turned out it was already in the standard library. Since this kind of answer is coming from you, I think I can safely assume that it is not. I'll accept this as an answer then. – Marko Grdinić Nov 05 '19 at 10:49
-
1Do not hesitate to open an issue listing the properties you wish you had for `Data.AVL.Map`. – gallais Nov 05 '19 at 14:48