繁体   English   中英

有没有办法在 Isabelle 中为自定义数据类型添加语法?

[英]Is there a way to add syntax for a custom datatype in Isabelle?

所以我有两种自定义数据类型:

datatype ('a, 't) action = ACTION (name: "'a") (args: "'t list") ("⌈_ _⌋")

datatype ('a, 't) multiaction = MULTIACTION "('a, 't) action multiset" ("⟨(_)⟩")

它们都使用它们给定的符号,但是每当我想以它们漂亮的打印格式使用这些数据结构时,它看起来有点多余。 例如:

value "⟨{#⌈a b⌋, ⌈c d⌋#}⟩"

我想要做的是在没有多重括号的情况下输入上述内容,因此它看起来像这样:

value "⟨⌈a b⌋, ⌈c d⌋⟩"

我尝试过的是使用语法:

syntax
  "_maction" :: "args ⇒ ('a, 't) multiaction" ("⟨_⟩" [0] 60)
translations
  "⟨x⟩" == "CONST MULTIACTION {#x#}"

但是当我尝试使用一些数据类型时:

value "⟨⌈''x'' [1,2,3::int]⌋⟩"

但是我得到了一个很好的错误,我不知道它为什么会发生。 我可以帮忙吗?

提前致谢!

也许,您希望将multiset语法提升为multiaction 在这种情况下,您可能还希望解除多集的相关定义(如注释中所述,理想情况下,您将希望为此使用datatype / multiset基础lift_definition ):

datatype ('a, 't) action = ACTION (name: "'a") (args: "'t list") ("⌈_ _⌋")
datatype ('a, 't) multiaction = MULTIACTION "('a, 't) action multiset"

(*this should not be lifted manually: use the integration of
the datatype and lifting infrastructure*)
fun add_multiaction :: 
  "('a, 'b) action ⇒ ('a, 'b) multiaction ⇒ ('a, 'b) multiaction"
  where "add_multiaction x (MULTIACTION xs) = MULTIACTION (add_mset x xs)"

abbreviation MAempty :: "('a, 't) multiaction" ("⟨#⟩") where
  "MAempty ≡ MULTIACTION {#}"

syntax
  "_multiaction" :: "args ⇒ ('a, 't) multiaction" ("⟨(_)⟩")
translations
  "⟨x, xs⟩" == "CONST add_multiaction x ⟨xs⟩"
  "⟨x⟩" == "CONST add_multiaction x ⟨#⟩"

value "⟨⌈''x'' [1,2,3::int]⌋, ⌈''x'' [1,2,3::int]⌋⟩"

我不得不承认,如果我完全理解您要达到的目标,我并不完全确定:我提供的第一个想法是基于对问题的不太透彻的理解。


伊莎贝尔版本:伊莎贝尔2021-RC6

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM