I am trying to define what it means for an item to be in a list. I wrote this case breakdown:
inductive NatList : Type
| nil : NatList
| cons : nat → NatList → NatList
def contains : nat -> NatList -> Prop
| _ NatList.nil := false
| x (NatList.cons x _) := true -- error here
| x (NatList.cons _ tail) := contains x tail
On the | x (NatList.cons x _) := true
line I get the error invalid pattern, 'x' already appeared in this pattern
. I can see that I have in fact used x
twice. But that's because I actually want it to pattern match to the case where the list item matches the query item. How do I rephrase what I want in a way that Lean will accept?
uncomputable
. $\endgroup$