Defining overloaded constants in Isabelle

坚强是说给别人听的谎言 提交于 2019-12-05 11:54:26

This kind of overloading looks like a perfect fit for type classes. First you define a type class for your desired function is_default:

class is_default =
  fixes is_default :: "'a ⇒ bool"

Then you introduce arbitrary instances. E.g., for Booleans

instantiation bool :: is_default
begin
definition "is_default (b::bool) ⟷ b"
instance ..
end

and lists

instantiation list :: (type) is_default
begin
definition "is_default (xs::'a list) ⟷ xs = []"
instance ..
end

Isabelle supports overloaded definitions by defining a constant name and then later providing the constant with new definitions for different types. This can be done with the consts command to define the constant name, and then the defs (overloaded) command to provide a partial definition.

For example:

consts is_default :: "'a ⇒ bool"

defs (overloaded) is_default_nat:
  "is_default a ≡ ((a::nat) = 0)"

defs (overloaded) is_default_option:
  "is_default a ≡ (a = None)"

The above will also work without the (overloaded) parameter, but will cause Isabelle to issue a warning.

The defs command is also given a name, which is the name of the theorem generated by Isabelle which contains the definition. This name can then be used in later proofs:

lemma "¬ is_default (Some 3)"
  by (clarsimp simp: is_default_option)

More information is available in section "Constants and definitions" in the Isablle/Isar reference manual. Additionally, there is a paper "Conservative Overloading in Higher-Order Logic" by Obua that discusses some of the implementation details and gotchas in having such a framework without sacrificing soundness.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!