为什么我不能在 Isabelle 中定义 nat?

Why can't I define nat in Isabelle?

我正在关注 tutorial for Isabelle,并输入了第 2.2.2 节中的以下示例:

theory FailedBasicAdditionProof
  imports Main
begin

datatype nat = 0 | Suc nat

fun add :: "nat ⇒ nat ⇒ nat" where
"add 0 n = n" |
"add (Suc m) n = Suc(add m n)"

lemma add_02: "add m 0 = m"
apply(induction m)
apply(auto)
  done
end

但出现错误

Legacy feature! Bad name binding: "nat.0"⌂ 
Legacy feature! Bad name binding: "nat.0"⌂ 
Bad name: "nat.0"

我做错了什么?

如果您碰巧看到 the datatype docs,就会完成完全相同的示例,只是使用单词 Zero 而不是数字 0

如果将 0 替换为 Zero,该示例应该有效。我认为这是一个命名约定,可能是后来更改或添加的。

正确的例子在这里:

theory CorrectBasicAdditionProof
  imports Main
begin

datatype nat = Zero | Suc nat

fun add :: "nat ⇒ nat ⇒ nat" where
"add Zero n = n" |
"add (Suc m) n = Suc(add m n)"

lemma add_02: "add m Zero = m"
apply(induction m)
apply(auto)
  done
end