Zulip Chat Archive

Stream: new members

Topic: atomicity


Julian Berman (Mar 24 2021 at 21:43):

What are atoms in lean, or what does atomicity mean? A couple of times I've made the mistake when pattern matching of doing:

def f : Nat  String
  | 0 => "foo"
  | n.succ => "bar"

instead of

def f : Nat  String
  | 0 => "foo"
  | n + 1 => "bar"

and lean will complain in the former case that "invalid pattern variable, must be atomic" -- I know there's @[matchPattern] or in lean3 @[pattern] which tells lean which things are OK to use in match patterns -- is there anything else I should know as to why lean likes the second example more than the first?

Mario Carneiro (Mar 24 2021 at 22:49):

I think that error means that you have named a variable with the nonatomic name n.succ

Mario Carneiro (Mar 24 2021 at 22:49):

Variable names (almost?) always have no namespaces

Mario Carneiro (Mar 24 2021 at 22:49):

Basically, it's not actually treating it as a projection

Bryan Gin-ge Chen (Mar 24 2021 at 23:00):

Right, this works:

def f : Nat  String
  | 0 => "foo"
  | Nat.succ n => "bar"

Julian Berman (Mar 24 2021 at 23:57):

I see! Interesting, thanks.


Last updated: Dec 20 2023 at 11:08 UTC