Association Lists #
This file defines association lists. An association list is a list where every element consists of a key and a value, and no two entries have the same key. The type of the value is allowed to be dependent on the type of the key.
This type dependence is implemented using sigma: The elements of the list are of type sigma β,
for some type index β.
Main definitions #
Association lists are represented by the alist structure. This file defines this structure and
provides ways to access, modify, and combine alists.
alist.keysreturns a list of keys of the alist.alist.has_memreturns membership in the set of keys.alist.eraseremoves a certain key.alist.insertadds a key-value mapping to the list.alist.unioncombines two association lists.
References #
alist β is a key-value map stored as a list (i.e. a linked list).
It is a wrapper around certain list functions with the added constraint
that the list have unique keys.
Instances for alist
- alist.has_sizeof_inst
- alist.has_mem
- alist.has_emptyc
- alist.inhabited
- alist.has_union
Equations
- alist.decidable_eq = λ (xs ys : alist β), _.mpr (list.decidable_eq xs.entries ys.entries)
keys #
mem #
empty #
The empty association list.
Equations
- alist.inhabited = {default := ∅}
singleton #
The singleton association list.
lookup #
Look up the value associated to a key in an association list.
Equations
- alist.lookup a s = list.lookup a s.entries
Equations
- alist.has_mem.mem.decidable a s = decidable_of_iff ↥((alist.lookup a s).is_some) _
replace #
Replace a key with a given value in an association list. If the key is not present it does nothing.
Equations
- alist.replace a b s = {entries := list.kreplace a b s.entries, nodupkeys := _}
Fold a function over the key-value pairs in the map.
Equations
- alist.foldl f d m = list.foldl (λ (r : δ) (a : sigma β), f r a.fst a.snd) d m.entries
erase #
Erase a key from the map. If the key is not present, do nothing.
Equations
- alist.erase a s = {entries := list.kerase a s.entries, nodupkeys := _}
insert #
Insert a key-value pair into an association list and erase any existing pair with the same key.
Equations
- alist.insert a b s = {entries := list.kinsert a b s.entries, nodupkeys := _}
extract #
Erase a key from the map, and return the corresponding value, if found.
Equations
- alist.extract a s = have this : (list.kextract a s.entries).snd.nodupkeys, from _, alist.extract._match_1 a (list.kextract a s.entries) this
- alist.extract._match_1 a (b, l) h = (b, {entries := l, nodupkeys := h})
union #
s₁ ∪ s₂ is the key-based union of two association lists. It is
left-biased: if there exists an a ∈ s₁, lookup a (s₁ ∪ s₂) = lookup a s₁.
Equations
- alist.has_union = {union := alist.union (λ (a b : α), _inst_1 a b)}