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 AList
s.
AList.keys
returns a list of keys of the alist.AList.membership
returns membership in the set of keys.AList.erase
removes a certain key.AList.insert
adds a key-value mapping to the list.AList.union
combines two association lists.
References #
Equations
- xs.instDecidableEq ys = ⋯.mpr inferInstance
keys #
mem #
The predicate a ∈ s
means that s
has a value associated to the key a
.
empty #
The empty association list.
Equations
- AList.instEmptyCollection = { emptyCollection := { entries := [], nodupKeys := ⋯ } }
singleton #
The singleton association list.
Equations
- AList.singleton a b = { entries := [⟨a, b⟩], nodupKeys := ⋯ }
Instances For
lookup #
Look up the value associated to a key in an association list.
Equations
- AList.lookup a s = List.dlookup a s.entries
Instances For
Equations
- AList.instDecidableMem a s = decidable_of_iff ((AList.lookup a s).isSome = true) ⋯
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 := ⋯ }
Instances For
Fold a function over the key-value pairs in the map.
Equations
- AList.foldl f d m = List.foldl (fun (r : δ) (a : Sigma β) => f r a.fst a.snd) d m.entries
Instances For
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 := ⋯ }
Instances For
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 := ⋯ }
Instances For
Recursion on an AList
, using insert
. Use as induction l
.
Equations
- AList.insertRec H0 IH { entries := [], nodupKeys := nodupKeys } = H0
- AList.insertRec H0 IH { entries := c :: l, nodupKeys := h } = ⋯.mpr (IH c.fst c.snd { entries := l, nodupKeys := ⋯ } ⋯ (AList.insertRec H0 IH { entries := l, nodupKeys := ⋯ }))
Instances For
extract #
Erase a key from the map, and return the corresponding value, if found.
Equations
- AList.extract a s = match List.kextract a s.entries, ⋯ with | (b, l), h => (b, { entries := l, nodupKeys := h })
Instances For
union #
Equations
- AList.instUnion = { union := AList.union }