Skip to content

Commit

Permalink
fix deriving handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kmill committed Nov 2, 2024
1 parent 8e59617 commit ef5ff12
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Mathlib/Tactic/DeriveTraversable.lean
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,17 @@ def mkOneInstance (n cls : Name) (tac : MVarId → TermElabM Unit)

/-- Make the new deriving handler depends on other deriving handlers. -/
def higherOrderDeriveHandler (cls : Name) (tac : MVarId → TermElabM Unit)
(deps : List DerivingHandlerNoArgs := [])
(deps : List DerivingHandler := [])
(mkInst : Name → Expr → TermElabM Expr := fun n arg => mkAppM n #[arg]) :
DerivingHandlerNoArgs := fun a => do
DerivingHandler := fun a => do
let #[n] := a | return false -- mutually inductive types are not supported yet
let ok ← deps.mapM fun f => f a
unless ok.and do return false
liftTermElabM <| mkOneInstance n cls tac mkInst
return true

/-- The deriving handler for `Functor`. -/
def functorDeriveHandler : DerivingHandlerNoArgs :=
def functorDeriveHandler : DerivingHandler :=
higherOrderDeriveHandler ``Functor deriveFunctor []

initialize registerDerivingHandler ``Functor functorDeriveHandler
Expand Down Expand Up @@ -298,7 +298,7 @@ def deriveLawfulFunctor (m : MVarId) : TermElabM Unit := do
mcm.refl

/-- The deriving handler for `LawfulFunctor`. -/
def lawfulFunctorDeriveHandler : DerivingHandlerNoArgs :=
def lawfulFunctorDeriveHandler : DerivingHandler :=
higherOrderDeriveHandler ``LawfulFunctor deriveLawfulFunctor [functorDeriveHandler]
(fun n arg => mkAppOptM n #[arg, none])

Expand Down Expand Up @@ -422,7 +422,7 @@ def deriveTraversable (m : MVarId) : TermElabM Unit := do
m.assign (mkAppN (mkConst n' (levels.map Level.param)) vars.toArray)

/-- The deriving handler for `Traversable`. -/
def traversableDeriveHandler : DerivingHandlerNoArgs :=
def traversableDeriveHandler : DerivingHandler :=
higherOrderDeriveHandler ``Traversable deriveTraversable [functorDeriveHandler]

initialize registerDerivingHandler ``Traversable traversableDeriveHandler
Expand Down Expand Up @@ -489,7 +489,7 @@ def deriveLawfulTraversable (m : MVarId) : TermElabM Unit := do
m.refl

/-- The deriving handler for `LawfulTraversable`. -/
def lawfulTraversableDeriveHandler : DerivingHandlerNoArgs :=
def lawfulTraversableDeriveHandler : DerivingHandler :=
higherOrderDeriveHandler ``LawfulTraversable deriveLawfulTraversable
[traversableDeriveHandler, lawfulFunctorDeriveHandler] (fun n arg => mkAppOptM n #[arg, none])

Expand Down

0 comments on commit ef5ff12

Please sign in to comment.