Skip to content

Commit d97c47d

Browse files
Add DelabM helper for instance synthesis checking
1 parent 9d77939 commit d97c47d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Mathlib/Util/DelabM.lean

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/-
2+
Copyright (c) 2025 Robert Maxton. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Robert Maxton
5+
-/
6+
module
7+
8+
public import Mathlib.Init
9+
public meta import Lean.PrettyPrinter.Delaborator.Builtins
10+
11+
/-! Delab helpers
12+
13+
Provides monadic functions in `DelabM` that can be factored out of their original application.
14+
-/
15+
16+
public meta section
17+
18+
/-- When the delab reader is pointed at an expression for an instance, returns `(true, t)`
19+
**iff** instance synthesis succeeds and produces a defeq instance; otherwise returns `(false, t)`.
20+
-/
21+
def delabCheckingCanonical : DelabM (Bool × Term) := do
22+
let instD ← delab
23+
let inst ← getExpr
24+
let type ← inferType inst
25+
-- if there is no synthesized instance, still return `false`
26+
-- (because `inst` is still non-canonical)
27+
let .some synthInst ← Meta.trySynthInstance type | return (false, instD)
28+
return (← Meta.isDefEq inst synthInst, instD)

0 commit comments

Comments
 (0)