Isabelle 从记录类型声明强制

Isabelle 从记录类型声明强制,isabelle,Isabelle,我有一张唱片 record foo = main_stuff :: "nat list" other_stuff :: "int" 如果f具有类型foo,我希望能够在必要时将f自动强制到main\u stuff字段中的nat列表中。例如,我希望能够有像f!5typecheck asmain\u f!5。我试过使用 declare [[coercion_enabled]] declare [[coercion main_stuff]] 但是类型检查仍然失败。我的基本问题是:Isabel

我有一张唱片

record foo =
  main_stuff :: "nat list"
  other_stuff :: "int"
如果
f
具有类型
foo
,我希望能够在必要时将
f
自动强制到
main\u stuff
字段中的
nat列表中。例如,我希望能够有像
f!5
typecheck as
main\u f!5
。我试过使用

declare [[coercion_enabled]]
declare [[coercion main_stuff]]

但是类型检查仍然失败。我的基本问题是:Isabelle强制与Isabelle记录类型兼容吗?

我看不出有任何理由认为记录应该是特殊的w.r.t强制,因为
foo
只是另一种类型(不管它是如何创建的)。事实上,你的例子对我很有用:

record foo =
  main_stuff :: "nat list"
  other_stuff :: "int"

abbreviation "x ≡ ⦇ main_stuff = [0], other_stuff = 1 ⦈"

declare [[coercion_enabled]]
declare [[coercion main_stuff]]

term "x ! 0"
最后一行的结果是

"main_stuff x ! 0"
  :: "nat"
而且

term "(f :: foo) ! 5"
一切正常。可能在您的示例中,
f
由于某种原因没有正确的类型