Zulip Chat Archive

Stream: Is there code for X?

Topic: Variant of #check command that unfold let expression


Asei Inoue (Mar 09 2025 at 15:46):

I ask this out of curiosity, but would it be possible to create a variant of the #check command that would expand let expressions?

For example, #check (let x := 1; x) does not show up as 1 : Nat, but could it be made to show up as 1 : Nat?

Aaron Liu (Mar 09 2025 at 15:47):

yes

Asei Inoue (Mar 09 2025 at 15:48):

How can I implement this?

Aaron Liu (Mar 09 2025 at 15:50):

write a wrapper for #check that zeta-reduces its argument first

Aaron Liu (Mar 09 2025 at 15:59):

import Lean

open Lean Meta Elab Term Command

elab tk:"#checkz" t:term : command => do
  -- copied from the `#check` command
  withoutModifyingEnv <| runTermElabM fun _ => withDeclName `_check do
  let e  elabTerm t none
  let e  zetaReduce e
  synthesizeSyntheticMVarsNoPostponing (ignoreStuckTC := true)
  -- Users might be testing out buggy elaborators. Let's typecheck before proceeding:
  withRef tk <| check e
  let e  levelMVarToParam ( instantiateMVars e)
  if e.isSyntheticSorry then
    return
  let type  inferType e
  logInfoAt tk m!"{e} : {type}"

#checkz let x := 1; x

Damiano Testa (Mar 09 2025 at 18:19):

There is also #simp that can be useful in similar situations.

Eric Wieser (Mar 09 2025 at 22:04):

Or you could use letI here

Asei Inoue (Mar 09 2025 at 22:56):

Thank you!!


Last updated: May 02 2025 at 03:31 UTC