代码之家  ›  专栏  ›  技术社区  ›  Denis

扩展标准类型和操作是个好主意吗?

  •  1
  • Denis  · 技术社区  · 8 年前

    ebool = bool ∪ {⊥} )以及类型的一组操作(连词等)。

    理论是这样的:

    theory EboolTest
      imports Main "~~/src/HOL/Library/Adhoc_Overloading"
    begin
    
    notation
      bot ("⊥")
    
    declare [[coercion_enabled]]
    
    typedef ebool = "UNIV :: bool option set" ..
    
    definition ebool :: "bool ⇒ ebool" where
      "ebool b = Abs_ebool (Some b)"
    
    declare [[coercion "ebool :: bool ⇒ ebool"]]
    
    instantiation ebool :: bot
    begin
    definition "⊥ ≡ Abs_ebool None"
    instance ..
    end
    
    free_constructors case_ebool for
      ebool
    | "⊥ :: ebool"
      apply (metis Rep_ebool_inverse bot_ebool_def ebool_def not_Some_eq)
      apply (smt Abs_ebool_inverse ebool_def iso_tuple_UNIV_I option.inject)
      by (simp add: Abs_ebool_inject bot_ebool_def ebool_def)
    
    lemmas ebool2_cases = ebool.exhaust[case_product ebool.exhaust]
    lemmas ebool3_cases = ebool.exhaust[case_product ebool.exhaust ebool.exhaust]
    
    fun ebool_and :: "ebool ⇒ ebool ⇒ ebool" (infixr "∧" 35) where
      "ebool_and a b = ebool (HOL.conj a b)"
    | "ebool_and False _ = False"
    | "ebool_and _ False = False"
    | "ebool_and ⊥ _ = ⊥"
    | "ebool_and _ ⊥ = ⊥"
    
    no_notation HOL.conj (infixr "∧" 35)
    consts "(∧)" :: "'a ⇒ 'a ⇒ 'a"
    adhoc_overloading "(∧)" HOL.conj
    adhoc_overloading "(∧)" ebool_and
    
    end
    

    以下工作正常:

    value "True ∧ (False::ebool)"
    value "True ∧ ⊥"
    

    ebool ,但我希望看到 bool :

    value "True ∧ False"
    

    1 回复  |  直到 8 年前
        1
  •  1
  •   larsrh    8 年前

    首先,我有点惊讶的是:

    consts "(∧)" :: "'a ⇒ 'a ⇒ 'a"
    

    (...) 符号是为系统保留的(公平地说,它确实打印了一个警告,除非你确切知道自己在做什么,否则忽略它们是不明智的。)

    adhoc_overloading 重载将由提供的语法 Main .

    还有其他选择。例如,可以使用粗体版本。这用于 this theory .

    或者你可以用另一个符号,比如 && .

    推荐文章