The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V34. The tactics of Mathlib

Mathlib.Tactic.DeriveTraversable

25 declarations. Mathlib docs · Source

Deriving handler for Traversable instances

This module gives deriving handlers for Functor, LawfulFunctor, Traversable, and LawfulTraversable. These deriving handlers automatically derive their dependencies, for example deriving LawfulTraversable all by itself gives all four.

opaque Mathlib.Deriving.Traversable.nestedMap E1 #

Lean.Expr → Lean.Expr → Lean.Expr → Lean.Elab.TermElabM Lean.Expr

nestedMap f α (List (Array (List α))) synthesizes the expression Functor.map (Functor.map (Functor.map f)). nestedMap assumes that α appears in (List (Array (List α))).

(Similar to nestedTraverse but for Functor.)

def Mathlib.Deriving.Traversable.mapField E1 #

Lean.Name → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Elab.TermElabM Lean.Expr

similar to traverseField but for Functor

def Mathlib.Deriving.Traversable.getAuxDefOfDeclName E1 #

Lean.Elab.TermElabM Lean.FVarId

Get the auxiliary local declaration corresponding to the current declaration. If there are multiple declarations it will throw.

def Mathlib.Deriving.Traversable.mapConstructor E1 #

Lean.Name →
  Lean.Name →
    Lean.Expr →
      Lean.Expr → Lean.Expr → List Lean.Expr → List (Bool × Lean.Expr) → Lean.MVarId → Lean.Elab.TermElabM Unit

similar to traverseConstructor but for Functor

def Mathlib.Deriving.Traversable.mkCasesOnMatch E1 #

Lean.Name →
  List Lean.Level →
    List Lean.Expr →
      Lean.Expr →
        List Lean.Expr →
          Lean.Expr → (Lean.Name → List Lean.FVarId → Lean.Elab.TermElabM Lean.Expr) → Lean.Elab.TermElabM Lean.Expr

Makes a match expression corresponding to the application of casesOn like:

match (motive := motive) indices₁, indices₂, .., (val : type.{univs} params₁ params₂ ..) with
| _, _, .., ctor₁ fields₁₁ fields₁₂ .. => rhss ctor₁ [fields₁₁, fields₁₂, ..]
| _, _, .., ctor₂ fields₂₁ fields₂₂ .. => rhss ctor₂ [fields₂₁, fields₂₂, ..]

This is convenient to make a definition with equation lemmas.

def Mathlib.Deriving.Traversable.getFVarIdsNotImplementationDetails E1 #

Lean.MetaM (List Lean.FVarId)

Get FVarIds which is not implementation details in the current context.

def Mathlib.Deriving.Traversable.getFVarsNotImplementationDetails E1 #

Lean.MetaM (List Lean.Expr)

Get Exprs of FVarIds which is not implementation details in the current context.

def Mathlib.Deriving.Traversable.mkMap E1 #

Lean.Name → Lean.MVarId → Lean.Elab.TermElabM Unit

derive the map definition of a Functor

def Mathlib.Deriving.Traversable.deriveFunctor E1 #

Lean.MVarId → Lean.Elab.TermElabM Unit

derive the map definition and declare Functor using this.

def Mathlib.Deriving.Traversable.mkInstanceNameForTypeExpr E1 #

Lean.Expr → Lean.Elab.TermElabM Lean.Name

Similar to mkInstanceName, but for a Expr type.

def Mathlib.Deriving.Traversable.mkOneInstance E1 #

Lean.Name →
  Lean.Name →
    (Lean.MVarId → Lean.Elab.TermElabM Unit) →
      (optParam (Lean.Name → Lean.Expr → Lean.Elab.TermElabM Lean.Expr) fun n arg ↦ liftM (Lean.Meta.mkAppM n #[arg])) →
        Lean.Elab.TermElabM Unit

Derive the cls instance for the inductive type constructor n using the tac tactic.

def Mathlib.Deriving.Traversable.higherOrderDeriveHandler E1 #

Lean.Name →
  (Lean.MVarId → Lean.Elab.TermElabM Unit) →
    optParam (List Lean.Elab.DerivingHandler) [] →
      (optParam (Lean.Name → Lean.Expr → Lean.Elab.TermElabM Lean.Expr) fun n arg ↦ liftM (Lean.Meta.mkAppM n #[arg])) →
        Lean.Elab.DerivingHandler

Make the new deriving handler depends on other deriving handlers.

def Mathlib.Deriving.Traversable.functorDeriveHandler E1 #

Lean.Elab.DerivingHandler

The deriving handler for Functor.

def Mathlib.Deriving.Traversable.deriveLawfulFunctor E1 #

Lean.MVarId → Lean.Elab.TermElabM Unit

Prove the functor laws and derive LawfulFunctor.

def Mathlib.Deriving.Traversable.lawfulFunctorDeriveHandler E1 #

Lean.Elab.DerivingHandler

The deriving handler for LawfulFunctor.

opaque Mathlib.Deriving.Traversable.nestedTraverse E1 #

Lean.Expr → Lean.Expr → Lean.Expr → Lean.Elab.TermElabM Lean.Expr

nestedTraverse f α (List (Array (List α))) synthesizes the expression traverse (traverse (traverse f)). nestedTraverse assumes that α appears in (List (Array (List α)))

def Mathlib.Deriving.Traversable.traverseField E1 #

Lean.Name → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Expr → Lean.Elab.TermElabM (Bool × Lean.Expr)

For a sum type inductive Foo (α : Type) | foo1 : List α → ℕ → Foo α | ... traverseField `Foo f `α `(x : List α) synthesizes traverse f x as part of traversing foo1.

def Mathlib.Deriving.Traversable.traverseConstructor E1 #

Lean.Name →
  Lean.Name →
    Lean.Expr →
      Lean.Expr →
        Lean.Expr → Lean.Expr → List Lean.Expr → List (Bool × Lean.Expr) → Lean.MVarId → Lean.Elab.TermElabM Unit

For a sum type inductive Foo (α : Type) | foo1 : List α → ℕ → Foo α | ... traverseConstructor `foo1 `Foo applInst f `α `β [`(x : List α), `(y : ℕ)] synthesizes foo1 <$> traverse f x <*> pure y.

def Mathlib.Deriving.Traversable.mkTraverse E1 #

Lean.Name → Lean.MVarId → Lean.Elab.TermElabM Unit

derive the traverse definition of a Traversable instance

def Mathlib.Deriving.Traversable.deriveTraversable E1 #

Lean.MVarId → Lean.Elab.TermElabM Unit

derive the traverse definition and declare Traversable using this.

def Mathlib.Deriving.Traversable.traversableDeriveHandler E1 #

Lean.Elab.DerivingHandler

The deriving handler for Traversable.

def Mathlib.Deriving.Traversable.simpFunctorGoal E1 #

Lean.MVarId →
  Lean.Meta.Simp.Context →
    optParam Lean.Meta.Simp.SimprocsArray ∅ →
      optParam (Option Lean.Meta.Simp.Discharge) none →
        optParam Bool true →
          optParam (Array Lean.FVarId) #[] →
            optParam Lean.Meta.Simp.Stats { } →
              Lean.MetaM (Option (Array Lean.FVarId × Lean.MVarId) × Lean.Meta.Simp.Stats)

Simplify the goal m using functor_norm.

def Mathlib.Deriving.Traversable.traversableLawStarter E1 #

Lean.MVarId →
  Lean.Name →
    Lean.MetaM Lean.Meta.Simp.Context →
      (Array Lean.FVarId → Lean.Meta.InductionSubgoal → Lean.MVarId → Lean.MetaM Unit) → Lean.MetaM Unit

Run the following tactic:

intro _ .. x
dsimp only [Traversable.traverse, Functor.map]
induction x <;> (the simp tactic corresponding to s) <;> (tac)

def Mathlib.Deriving.Traversable.deriveLawfulTraversable E1 #

Lean.MVarId → Lean.Elab.TermElabM Unit

Prove the traversable laws and derive LawfulTraversable.

def Mathlib.Deriving.Traversable.lawfulTraversableDeriveHandler E1 #

Lean.Elab.DerivingHandler

The deriving handler for LawfulTraversable.