Lean4
/-- Given an expression that's either a native projection or a registered projection
function, gives (1) the name of the structure type, (2) the index of the projection, and
(3) the object being projected. -/
def getProjectedExpr (e : Expr) : MetaM (Option (Name × Nat × Expr)) := do
if let .proj S i x := e then
return (S, i, x)
if let .const fn _ := e.getAppFn then
if let some info← getProjectionFnInfo? fn then
if e.getAppNumArgs == info.numParams + 1 then
if let some (ConstantInfo.ctorInfo fVal) := (← getEnv).find? info.ctorName then
return (fVal.induct, info.i, e.appArg!)
return none