Zulip Chat Archive
Stream: new members
Topic: typeof
Steven Shaw (Jun 27 2023 at 23:46):
Hi. I'm wondering if there might be a typeOf
operator in Lean. I might want to confirm the type of an expression using an example
, something like:
example: typeOf (String.append) = (String → String → String) := rfl
Scott Morrison (Jun 27 2023 at 23:50):
def typeOf {α} (_ : α) := α
example : typeOf String.append = (String → String → String) := rfl
Kyle Miller (Jun 28 2023 at 00:42):
There should be a typeof%
"function" that gives you the type itself. I don't remember if it has an underscore in the name (on my phone)
Steven Shaw (Jun 28 2023 at 00:51):
Thanks, it's great to see how typeOf
can be implemented in Lean itself. As for the built-in function, it looks like it's type_of%
. I can't navigate to its definition, so I imagine it's a compiler intrinsic.
Kyle Miller (Jun 28 2023 at 01:26):
It's called a "term elaborator" and it's something you can even write yourself! (It's like a compiler intrinsic that's a macro)
Mario Carneiro (Jun 28 2023 at 01:49):
Go to definition should work on it, but you need to have import Lean
so that the declaration is in the environment
Steven Shaw (Jun 28 2023 at 01:56):
Thanks, using import Lean
, I can now navigate to the definition!
Last updated: Dec 20 2023 at 11:08 UTC