lean icon indicating copy to clipboard operation
lean copied to clipboard

`expr.fold` uneccesarily(?) is not defined for `pexpr`s

Open khoek opened this issue 5 years ago • 3 comments

The statement of expr.fold is

meta constant expr.fold {α : Type} : expr → α → (expr → nat → α → α) → α

which prohibits folding over pexprs. Is there any good reason for this (the only thing I can think of is a possible VM representation difference?).

If not, let's change it.

khoek avatar Apr 21 '20 15:04 khoek

No, I was simply too lazy

Kha avatar Apr 21 '20 15:04 Kha

I think quite a few of the expr functions have this unnecessary restriction and should be generalized. But it takes someone knowledgeable to know which are which, or to carefully check the source to confirm.

robertylewis avatar Apr 21 '20 15:04 robertylewis

Under the hood pexpr is exactly the same data structure as expr. The types are just there to help you not to confuse them (and e.g. call infer_type on a pre-expression). They have the same representation, and you can (more or less) safely cast between them. If you want to use such a function (in mathlib), just use unchecked_cast:

meta def pexpr.fold {α : Type u} : pexpr → α → (pexpr → nat → α → α) → α :=
unchecked_cast expr.fold

gebner avatar Apr 21 '20 16:04 gebner