Zulip Chat Archive
Stream: lean4
Topic: coercion to function notation
Kevin Buzzard (Jun 12 2024 at 22:03):
I can't get ⇑f
notation. What am I doing wrong?
structure AutomorphicForm where
toFun : Nat → Int
cool_axiom : toFun 37 = 42
variable (f : AutomorphicForm) (n : Nat)
namespace AutomorphicForm
-- #check f n -- error
#check f.toFun n -- f.toFun n : Int
-- #check ⇑f n -- error
instance : CoeFun AutomorphicForm (fun _ => Nat → Int) :=
⟨toFun⟩
#check f n -- f.toFun n : Int
#check f.toFun n -- f.toFun n : Int
#check ⇑f n -- f.toFun n : Int
attribute [coe] toFun
#check f n -- ↑f n : Int
#check f.toFun n -- ↑f n : Int
#check ⇑f n -- ↑f n : Int
-- How do I get `⇑f` ?
llllvvuu (Jun 12 2024 at 22:10):
#check ⇑f
works for me
instance : CoeFun AutomorphicForm (fun _ => Nat → Int) :=
⟨toFun⟩
#check f n -- f.toFun n : Int
#check f.toFun n -- f.toFun n : Int
#check ⇑f n -- f.toFun n : Int
#check ⇑f -- f.toFun : Nat → Int
attribute [coe] toFun
#check f n -- ↑f n : Int
#check f.toFun n -- ↑f n : Int
#check ⇑f n -- ↑f n : Int
#check ⇑f -- ↑f : Nat → Int
Floris van Doorn (Jun 12 2024 at 23:12):
I think ⇑
is just always printed as ↑
?
Eric Wieser (Jun 13 2024 at 00:00):
import Lean.Elab.Command
structure AutomorphicForm where
toFun : Nat → Int
cool_axiom : toFun 37 = 42
variable (f : AutomorphicForm) (n : Nat)
namespace AutomorphicForm
-- #check f n -- error
#check f.toFun n -- f.toFun n : Int
-- #check ⇑f n -- error
instance : CoeFun AutomorphicForm (fun _ => Nat → Int) :=
⟨toFun⟩
#check f n -- f.toFun n : Int
#check f.toFun n -- f.toFun n : Int
#check ⇑f n -- f.toFun n : Int
-- this is what `@[coe]` does, but we use `.coeFun`
run_cmd Lean.Elab.Command.liftTermElabM do
Lean.Meta.registerCoercion ``AutomorphicForm.toFun
(some { numArgs := 1, coercee := 0, type := .coeFun })
#check ⇑f -- ⇑f : Nat → Int
#check f n -- f n : Int
#check f.toFun n -- f n : Int
#check ⇑f n -- f n : Int
Eric Wieser (Jun 13 2024 at 00:01):
We never bothered adding @[coe_fun]
to match @[coe]
, because mathlib only uses it for DFunLike.coe
anyway.
Last updated: May 02 2025 at 03:31 UTC