Utilities for lists of sigmas #
This file includes several ways of interacting with List (Sigma β), treated as a key-value store.
If α : Type* and β : α → Type*, then we regard s : Sigma β as having key s.1 : α and value
s.2 : β s.1. Hence, List (Sigma β) behaves like a key-value store.
Main Definitions #
List.keysextracts the list of keys.List.NodupKeysdetermines if the store has duplicate keys.List.lookup/lookup_allaccesses the value(s) of a particular key.List.kreplacereplaces the first value with a given key by a given value.List.keraseremoves a value.List.kinsertinserts a value.List.kunioncomputes the union of two stores.List.kextractreturns a value with a given key and the rest of the values.
Determines whether the store uses a key several times.
Equations
- List.NodupKeys l = List.Nodup (List.keys l)
Instances For
dlookup a l is the first value in l corresponding to the key a,
or none if no such element exists.
Equations
- List.dlookup a [] = none
- List.dlookup a ({ fst := a', snd := b } :: l) = if h : a' = a then some (Eq.recOn h b) else List.dlookup a l
Instances For
lookup_all a l is the list of all values in l corresponding to the key a.
Equations
- List.lookupAll a [] = []
- List.lookupAll a ({ fst := a', snd := b } :: l) = if h : a' = a then Eq.recOn h b :: List.lookupAll a l else List.lookupAll a l
Instances For
Replaces the first value with key a by b.
Equations
- List.kreplace a b = List.lookmap fun (s : Sigma β) => if a = s.fst then some { fst := a, snd := b } else none
Instances For
Remove the first pair with the key a.
Equations
- List.kerase a = List.eraseP fun (s : Sigma β) => decide (a = s.fst)
Instances For
Insert the pair ⟨a, b⟩ and erase the first pair with the key a.
Equations
- List.kinsert a b l = { fst := a, snd := b } :: List.kerase a l
Instances For
Finds the first entry with a given key a and returns its value (as an Option because there
might be no entry with key a) alongside with the rest of the entries.
Equations
- List.kextract a [] = (none, [])
- List.kextract a (s :: l) = if h : s.fst = a then (some (Eq.recOn h s.snd), l) else match List.kextract a l with | (b', l') => (b', s :: l')
Instances For
Remove entries with duplicate keys from l : List (Sigma β).
Equations
- List.dedupKeys = List.foldr (fun (x : Sigma β) => List.kinsert x.fst x.snd) []
Instances For
kunion l₁ l₂ is the append to l₁ of l₂ after, for each key in l₁, the
first matching pair in l₂ is erased.
Equations
- List.kunion [] x = x
- List.kunion (s :: l₁) x = s :: List.kunion l₁ (List.kerase s.fst x)