Theoremdedup_foldl_lookup
Statement
theorem dedup_foldl_lookup (k : String) : ∀ (l acc : List Bind),
fmLookup (l.foldl (fun acc (k, j) => acc.filter (·.1 != k) ++ [(k, j)]) acc) k =
match lookupLast l k with
| some j => some j
| none => fmLookup acc k
| [], acc => by simp [lookupLast, fmLookup]
| (k', j) :: l, acc => by
simp only [List.foldl_cons]
rw [dedup_foldl_lookup k l]
have hl : lookupLast ((k', j) :: l) k =
match lookupLast l k with
| some x => some x
| none => if k' = k then some j else noneProof
by
unfold lookupLast
rw [List.reverse_cons, fmLookup_append']
cases fmLookup l.reverse k <;> by_cases h : k' = k <;> simp [fmLookup, h]
rw [hl]
cases lookupLast l k with
| some x => rfl
| none =>
simp only
rw [fmLookup_append_single]
by_cases h : k' = k <;> simp [h]Proved with tactics, which Lean expands into a proof term that its kernel checks.
Theorems it uses
Used by
In StandardElmMech/Eff/MkObj.lean: A76: mkObj ignores the order of distinct keys (a76_mkObj_perm), a lookup finds the last binding (lookup_mkObj), and decoding ignores keys outside the record type (a76_dec_extra_key).
A Standard Definition of Elm? (Draft version 0.4) © Rupert Smith. The text is licensed under CC BY 4.0: share and adapt it freely, with credit and a link to the licence.