簡體   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