refactor: move isMonad? to AppBuilder.lean
This commit is contained in:
parent
e2028e64ff
commit
c747230e28
2 changed files with 11 additions and 25 deletions
|
|
@ -625,31 +625,6 @@ private def isTypeApp? (type : Expr) : TermElabM (Option (Expr × Expr)) := do
|
|||
| Expr.app m α _ => pure (some ((← instantiateMVars m), (← instantiateMVars α)))
|
||||
| _ => pure none
|
||||
|
||||
/-
|
||||
private def isMonad? (type : Expr) : TermElabM (Option IsMonadResult) := do
|
||||
let type ← withReducible $ whnf type
|
||||
match type with
|
||||
| Expr.app m α _ =>
|
||||
try
|
||||
let monadType ← mkAppM `Monad #[m]
|
||||
let result ← trySynthInstance monadType
|
||||
match result with
|
||||
| LOption.some inst => pure (some { m := m, α := α, inst := inst })
|
||||
| _ => pure none
|
||||
catch _ => pure none
|
||||
| _ => pure none
|
||||
-/
|
||||
|
||||
private def isMonad? (m : Expr) : TermElabM (Option Expr) :=
|
||||
try
|
||||
let monadType ← mkAppM `Monad #[m]
|
||||
let result ← trySynthInstance monadType
|
||||
match result with
|
||||
| LOption.some inst => pure inst
|
||||
| _ => pure none
|
||||
catch _ =>
|
||||
pure none
|
||||
|
||||
def synthesizeInst (type : Expr) : TermElabM Expr := do
|
||||
let type ← instantiateMVars type
|
||||
match (← trySynthInstance type) with
|
||||
|
|
|
|||
|
|
@ -445,6 +445,17 @@ def mkImpCongrCtx (h₁ h₂ : Expr) : MetaM Expr :=
|
|||
def mkForallCongr (h : Expr) : MetaM Expr :=
|
||||
mkAppM ``forallCongr #[h]
|
||||
|
||||
/-- Return instance for `[Monad m]` if there is one -/
|
||||
def isMonad? (m : Expr) : MetaM (Option Expr) :=
|
||||
try
|
||||
let monadType ← mkAppM `Monad #[m]
|
||||
let result ← trySynthInstance monadType
|
||||
match result with
|
||||
| LOption.some inst => pure inst
|
||||
| _ => pure none
|
||||
catch _ =>
|
||||
pure none
|
||||
|
||||
/-- Return `(n : type)`, a numeric literal of type `type`. The method fails if we don't have an instance `OfNat type n` -/
|
||||
def mkNumeral (type : Expr) (n : Nat) : MetaM Expr := do
|
||||
let u ← getDecLevel type
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue