Elm Exactly

TheoremtypBinds_fold

StandardElmMech/Stat/RefuseTypes.lean:755, Type declarations · term proof

Statement

theorem typBinds_fold (C : Ctx) : ∀ (seg : List BTypBind) (VEs : List ValEnv) (TEs : List TyEnv) (acc : TyEnv),
    elabTypBinds C seg = some (VEs, TEs) → (seg.map (·.c)).Nodup →
    (∀ k, k ∉ seg.map (·.c) → FMap.find? (TEs.foldl FMap.modify acc) k = FMap.find? acc k) ∧
    (∀ tb ∈ seg, ∃ τ X, elabTy (C.plusU (aliasVars tb)) tb.t = some τ ∧
      FMap.find? (TEs.foldl FMap.modify acc) tb.c = some (TyFcn.canon ⟨aliasVars tb, τ⟩, X))
  | [], VEs, TEs, acc, h, _ => by
    simp only [elabTypBinds, Option.some.injEq, Prod.mk.injEq] at h
    obtain ⟨rfl, rfl⟩

Proof

h
    simp
  | tb :: rest, VEs, TEs, acc, h, hnd => by
    simp only [elabTypBinds] at h
    split at h
    · rename_i VE1 TE1 VEs' TEs' h1 h2
      simp only [Option.some.injEq, Prod.mk.injEq] at h
      obtain ⟨rfl, rfl⟩ := h
      obtain ⟨τ, X, hτ, rfl⟩ := typBind_shape C tb VE1 TE1 h1
      simp only [List.map_cons, List.nodup_cons] at hnd
      have ih := typBinds_fold C rest VEs' TEs' (FMap.modify acc [(tb.c, (TyFcn.canon ⟨aliasVars tb, τ⟩, X))]) h2 hnd.2
      simp only [List.foldl_cons]
      refine ⟨fun k hk => ?_, fun tb' htb' => ?_⟩
      · simp only [List.map_cons, List.mem_cons, not_or] at hk
        rw [ih.1 k hk.2, FMap.find?_modify]
        simp [FMap.find?, Ne.symm hk.1]
      · rcases List.mem_cons.mp htb' with rfl | hr
        · refine ⟨τ, X, hτ, ?_⟩
          rw [ih.1 _ hnd.1, FMap.find?_modify]
          simp [FMap.find?]
        · exact ih.2 tb' hr
    · cases h

Proved by a term, which Lean's kernel checks directly.

Theorems it uses

Used by

In StandardElmMech/Stat/RefuseTypes.lean: Refusals by type expressions (aliases, constructor arguments, annotations, ports) and by the type of main (typesFailB, mainFailB), for every choice of generated names and variable sorts.

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.