Elm Exactly

Theorema76_mkObj_perm

StandardElmMech/Eff/MkObj.lean:109, Keeping the last binding of each key · tactic proof

A76: objects are unordered: the order of an object's distinct keys does not matter.

Statement

theorem a76_mkObj_perm {kvs kvs' : List Bind} (hp : kvs.Perm kvs') (hn : (kvs.map (·.1)).Nodup) :
    BVal.mkObj kvs = BVal.mkObj kvs'

Proof

by
  have hn' : (keysOf kvs').Nodup := by unfold keysOf; exact (hp.map Prod.fst).nodup_iff.mp hn
  unfold BVal.mkObj
  rw [dedupLastByKey_nodup kvs hn, dedupLastByKey_nodup kvs' hn']
  congr 1
  apply List.Perm.eq_of_pairwise _ (sortByKey_sorted kvs) (sortByKey_sorted kvs')
  · exact ((sortByKey_perm kvs).trans hp).trans (sortByKey_perm kvs').symm
  · intro a b ha hb hab hba
    have ha' : a ∈ kvs := (sortByKey_perm kvs).mem_iff.mp ha
    have hb' : b ∈ kvs := hp.mem_iff.mpr ((sortByKey_perm kvs').mem_iff.mp hb)
    exact mem_of_keys_nodup_eq hn ha' hb' (String.le_antisymm hab hba)

Proved with tactics, which Lean expands into a proof term that its kernel checks.

Theorems it uses

About ruling A76 of the book, where the implementations disagreed or were silent and the definition decides.

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.