给出以下假设:
Variable A : finType.
Variable B : finType.
Variable C : finType.
和一条记录定义为:
Record example := Example {
example_A : A;
example_B : B;
example_C : C;
}.
直觉上,似乎示例也必须是finType
。
看看其他代码库,我看到人们使用格式构造来推导finType
的记录仅包含一个非证明性术语
Definition <record>_subType := Eval hnf in [subtype for <record-accessor>].
Definition <record>_finMixin := Eval hnf in [finMixin of <record> by <:].
但是在这种情况下,记录有多个字段。
是否有一种自动获取记录的fintype的方法,如果没有,如何为记录获取fintype?
答案 0 :(得分:3)
可以通过显示您的类型是实现该接口的某种其他类型的撤回来得出数学组件中的许多接口实现。在您的示例中,我们只需要将记录转换为元组即可。
From mathcomp Require Import
ssreflect ssrfun ssrbool ssrnat eqtype seq choice fintype.
Variables A B C : finType.
Record example := Example {
example_A : A;
example_B : B;
example_C : C
}.
Definition prod_of_example e :=
let: Example a b c := e in (a, b, c).
Definition example_of_prod p :=
let: (a, b, c) := p in Example a b c.
Lemma prod_of_exampleK : cancel prod_of_example example_of_prod.
Proof. by case. Qed.
Definition example_eqMixin :=
CanEqMixin prod_of_exampleK.
Canonical example_eqType :=
Eval hnf in EqType example example_eqMixin.
Definition example_choiceMixin :=
CanChoiceMixin prod_of_exampleK.
Canonical example_choiceType :=
Eval hnf in ChoiceType example example_choiceMixin.
Definition example_countMixin :=
CanCountMixin prod_of_exampleK.
Canonical example_countType :=
Eval hnf in CountType example example_countMixin.
Definition example_finMixin :=
CanFinMixin prod_of_exampleK.
Canonical example_finType :=
Eval hnf in FinType example example_finMixin.
在此代码段的结尾,example
被声明为finType
。 (请注意,eqType
,choiceType
等的所有其他声明也是必需的,因为finType
是这些声明的子类。)