【发布时间】:2015-10-02 14:25:13
【问题描述】:
我想将我的程序构建为抽象模块,并编写使用抽象类型的函数。但是我不能使用match 来破坏抽象类型,所以我必须创建某种反转引理,但我也不能使用match。我试图将我的问题归结为:
首先创建一个Module Type 可以被decidable 类型使用。
Require Import Decidable.
Module Type decType.
Parameter T : Type.
Axiom decT : forall (a b:T), decidable (a=b).
End decType.
这里是一个例子:nat 是可判定的。但目的是编写plus 等,仅针对抽象类型。 (我已删除参数zero、Succ 及其要求,以使此处的示例最小化)。
Require Peano_dec.
Module nat_dec <: decType.
Definition T := nat.
Definition decT := Peano_dec.dec_eq_nat.
End nat_dec.
现在我的问题是:我想编写一个在 decType 模块上参数化的模块,其函数返回 true 如果 a=b 和 false 否则。由于a 和b 属于decType,这应该是可判定的(因此是可计算的,或者?),但我该如何写beq?
Module decBool (M: decType).
Import M.
Definition beq (a b:T) : bool :=
???
.
End decBool.
到目前为止,我的想法是我必须向 decType 模块类型添加一个布尔函数,如下所示:
Module Type decType.
Parameter T : Type.
Axiom decT : forall (a b:T), decidable (a=b).
Parameter decB : forall (a b:T), {a=b}+{a<>b}.
End decType.
然后在上面的nat_dec模块中定义decB。
这是必须要做的吗(即定义函数 decB)?不通过返回 bool 的函数,就根本不可能使用类型是可确定的抽象事实吗?
【问题讨论】:
标签: coq