Zulip Chat Archive

Stream: lean4

Topic: Postfix + dot notation


Peter Nelson (Jun 30 2023 at 11:20):

Is there a way to define a postfix operator that binds more strongly than dot notation? I would like to do something like the following without the need for parentheses around the n*.

import Mathlib.Data.Nat.Basic

def add_five :    := fun x  x+5

postfix:max "*" => add_five

lemma star_succ (n : ) : (n*).succ = n.succ* := by
  simp [add_five]

-- lemma star_succ' (n : ℕ) : n*.succ = n.succ* := by sorry
-- breaks without parentheses

Kyle Miller (Jun 30 2023 at 11:59):

It seems that the problem is an ambiguity in n*.succ, since it could mean n * .succ, since .succ is valid syntax.

This works fine:

postfix:max "**" => add_five

lemma star_succ (n : ) : n**.succ = n.succ** := by
  simp [add_five]

Peter Nelson (Jun 30 2023 at 13:03):

Thanks!


Last updated: Dec 20 2023 at 11:08 UTC