What is an Isabelle/HOL subtype? What Isar commands produce subtypes?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 06:52:47
Andreas Lochbihler

Isabelle/HOL does not have subtypes in the sense of substitutability. This means that if you need a value of type a, then you have to provide a value of type a - you cannot get along with a different type b. In particular, Isabelle does not have the notion of subtype where the values of the subtype satisfy some additional property.

There are some ways to emulate certain aspects of subtypes, and this is where the notion subtype is used:

  1. Substitution of type parameters allows you to sometimes create the illusion of subtyping. The record package uses this to extend records such that one can use an extended record q in place of the non-extended record r. Internally, the additional fields of q are stuffed into an additional type parameter of a generalisation of r's record type. Technically, there's no subtype polymorphism going on; consequently, the order of extending records matters.

  2. typedef introduces a new type t whose type universe is a non-empty subset of the values of some existing HOL type a. Sometimes, this is referred to as t being a subtype of a, but you do not get substitutability. You always have to explicitly mention the embedding morphism Rep_t when you want to use a value of t as one of a. It does not matter whether you define your type with typedef or by some other means, any injective function can serve as such a coercion.

  3. Coercive subtyping as described in the Isabelle Reference Manual (section 12.4) makes Isabelle infer and insert such coercions automatically. This only works both the type and the subtype are type constructors without arguments. Use declare [[coercion_enabled]] to enable coercive subtyping and register your coercion function with declare [[coercion Rep_t]]. Thus, you do not have to insert the embedding functions yourself.

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