如何在 Isabelle 的类型类定义中包含多个任意类型?

How can I have multiple arbitrary types in a typeclass definiton in Isabelle?

所以我想定义一个看起来像

的类型class
class action =
   fixes name :: "'a => 'b"
     and params :: "'a => 'p"

这样我就可以创建数据类型的实例,例如

datatype ('b, 'c, 'd) actionT1 = Act 'b 'c 'd

我会在哪里

name (Act n c d) = n
params (Act n c d) = (c,d)

所以在这种情况下,class 中的类型 'p 对应于 'c \times 'd 而 class 中的 'b 对应于 'b 在示例操作中。

现在我可以在各种函数中使用函数 nameparams,例如:

fun equalParams :: "'a :: action => 'a => bool" where
"equalParams a b = (params a = params b)"

不幸的是,我实际上无法做到这一点,因为 Isabelle 似乎只接受一种任意数据类型。此外,如果我尝试执行以下操作:

instantiation (string, int, int) actionT1 :: action
begin
.
.
.
end

我收到一条错误消息,提示 Isabelle 需要类型构造函数,但 ( 找到了。 如何在 Isabelle 中实现此功能?

除非您想使用字体,否则您也可以使用语言环境。这避免了 Isabelle class 系统的一些限制。你的情况:

text ‹Create the locale and define equalParams within the body of the locale›
locale mylocale =
   fixes name :: "'a => 'b"
     and params :: "'a => 'p"
begin
fun equalParams :: "'a => 'a => bool" where
"equalParams a b = (params a = params b)"
end

datatype ('b, 'c, 'd) actionT1 = Act (name: 'b) (c: 'c) (d: 'd)

abbreviation params where
  ‹params a ≡ (c a, d a)›


text ‹Instantiate the locale with our parameters.›

text ‹First in a named interpretation:›
interpretation action: mylocale where name = name and params = params
  by unfold_locales

term action.equalParams



text ‹Second in a unnamed interpretation:›
interpretation mylocale where name = name and params = params
  by unfold_locales

term equalParams

有关语言环境的更多详细信息,请参阅 documentation