Theoremlookup_insertByKey
Statement
theorem lookup_insertByKey (k : String) (b : Bind) : ∀ m : List Bind, b.1 ∉ keysOf m →
fmLookup (insertByKey b m) k = if b.1 = k then some b.2 else fmLookup m k
| [], _ => by obtain ⟨a, v⟩Proof
b; by_cases h : a = k <;> simp [insertByKey, fmLookup, h]
| c :: rest, hn => by
obtain ⟨a, v⟩ := b
obtain ⟨c1, c2⟩ := c
simp only [keysOf, List.map_cons, List.mem_cons, not_or] at hn
unfold insertByKey
split
· by_cases h : a = k <;> simp [fmLookup, h]
· simp only [fmLookup]
rw [lookup_insertByKey k (a, v) rest hn.2]
by_cases hc : c1 = k
· subst hc
have : a ≠ c1 := hn.1
simp [this]
· have : (c1 == k) = false := by simpa using hc
simp [this]Proved by a term, which Lean's kernel checks directly.
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.