Lean4
/-- If `e` is the form `@R .. x y`, where `R` is a reflexive
relation, return `some (R, x, y)`.
As a special case, if `e` is `@HEq α a β b`, return ``some (`HEq, a, b)``. -/
def _root_.Lean.Expr.relSidesIfRefl? (e : Expr) : MetaM (Option (Name × Expr × Expr)) := do
if let some (_, lhs, rhs) := e.eq? then
return (``Eq, lhs, rhs)
if let some (lhs, rhs) := e.iff? then
return (``Iff, lhs, rhs)
if let some (_, lhs, _, rhs) := e.heq? then
return (``HEq, lhs, rhs)
if let .app (.app rel lhs) rhs := e then
unless (← (reflExt.getState (← getEnv)).getMatch rel).isEmpty do
match rel.getAppFn.constName? with
| some n =>
return some (n, lhs, rhs)
| none =>
return none
return none