Isabelle/HOL错误类型统一失败:类型冲突;nat";及“设置”;应用程序中的类型错误:操作数类型不兼容

Isabelle/HOL错误类型统一失败:类型冲突;nat";及“设置”;应用程序中的类型错误:操作数类型不兼容,isabelle,Isabelle,我对伊莎贝尔真的很陌生,这是我的问题 theory MyTheory3 imports Main begin (* 3.1) a) define a type natpair, whose elements are pairs of natural numbers.*) datatype natpair = Natpair "nat × nat" (*3.1 b)define a function of type natpair ⇒ nat that returns t

我对伊莎贝尔真的很陌生,这是我的问题

theory MyTheory3
  imports Main
begin
(* 3.1) a) define a type natpair, whose elements are pairs of natural numbers.*)
datatype natpair = Natpair "nat × nat"

(*3.1 b)define a function of type natpair ⇒ nat that returns the sum of the elements of a pair of natural
numbers.*)
definition natpair_sum :: "natpair ⇒ nat" where
  "Natpair((a::nat) × (b::nat)) = a + b"
end
我得到了错误

类型统一失败:类型“nat”和“set”冲突

应用程序中的类型错误:操作数类型不兼容

运算符:(×):??“一个集合”⇒ ??'b组⇒ (??'a×??'b)集合操作数:a ::纳特

另外,有人能给我展示一个带有参数化 建造师

提前谢谢
您是nuric

您的代码有几个问题:

  • 运算符
    (×)
    不是成对的构造函数,而是集合的笛卡尔积;对是使用语法
    (a,b)
    对a b
    构造的
  • 定义
    natpair\u sum
    未在公式中使用其名称,即正确的语法为
    definition natpair\u sum::“natpair⇒ nat“where”natpair\u sum…=…”
  • 不允许在
    定义的左侧进行模式匹配
    ;您可以使用
    定义
    右侧的
    大小写
    构造,也可以使用函数
  • 无需为该对的组件添加类型注释
  • 作为示例,这里有两种可能的
    natpair\u sum
    定义:

      definition natpair_sum :: "natpair ⇒ nat" where
        "natpair_sum np = (case np of Natpair (a, b) ⇒ a + b)"
    
      fun natpair_sum :: "natpair ⇒ nat" where
        "natpair_sum (Natpair (a, b)) = a + b"
    
    至于你的最后一个问题,我不太清楚你所说的“带有参数化构造函数的natpair示例”是什么意思
    Natpair
    已经是一个数据构造函数,它将一对
    nat
    作为唯一的参数