Zulip Chat Archive

Stream: lean4

Topic: binderIdent vs Ident


Patrick Massot (Nov 16 2023 at 16:19):

How to turn an ident into a binderIdent?

Patrick Massot (Nov 16 2023 at 16:20):

Knowing the definition is syntax binderIdent := ident <|> hole.

Jannis Limperg (Nov 16 2023 at 16:45):

import Lean

open Lean

def toBinderIdent (i : Ident) : CoreM (TSyntax ``binderIdent) :=
  `(binderIdent| $i:ident)

That is to say, you probably just need to annotate your use site with :ident.

Patrick Massot (Nov 16 2023 at 16:55):

Thanks! I wasn't able to use the annotation suggestion but the function works fine.

Kyle Miller (Nov 16 2023 at 17:09):

I don't think there's any reason to run this in a monad, so here's an alternative:

def toBinderIdent (i : Ident) : TSyntax ``binderIdent := Unhygienic.run <|
  withRef i `(binderIdent| $i:ident)

(The withRef is to tag the resulting binderIdent with the source position of i. Jannis's could have that too.)

Patrick Massot (Nov 16 2023 at 17:11):

Thanks!


Last updated: Dec 20 2023 at 11:08 UTC