Zulip Chat Archive

Stream: lean4

Topic: Coercion notation not showing


Son Ho (Apr 04 2024 at 13:01):

I defined a custom Coe instance below, but for some reason this coercion don't get pretty printed with the "up arrow" in goals.

import Lean

structure Foo :=
  x : Int
  y : Bool

instance : Coe Foo Int where
  coe v := v.x

example (x : Foo) (y : Int) (h : (x) = y) : True := by
  /-
    Goal:
    x : Foo
    y : Int
    h : x.x = y  -- HERE: I expected: h : (↑x) = y
    ⊢ True
  -/
  trivial

Does someone know where this might come from/how I could get the pretty-printing working?

Ruben Van de Velde (Apr 04 2024 at 13:09):

You need to add @[coe] to the function, though I'm not sure what it should be here

Ruben Van de Velde (Apr 04 2024 at 13:09):

attribute [coe] Foo.x, maybe

Son Ho (Apr 04 2024 at 13:24):

It works, thanks!


Last updated: May 02 2025 at 03:31 UTC