0
的元素,类型为A
的一个简单的归纳定义:在勒柯克,如何构建“SIG”型
Inductive A: Set := mkA : nat-> A.
(*get ID of A*)
Function getId (a: A) : nat := match a with mkA n => n end.
和子类型的定义:
(* filter that test ID of *A* is 0 *)
Function filter (a: A) : bool := if (beq_nat (getId a) 0) then true else false.
(* cast bool to Prop *)
Definition IstrueB (b : bool) : Prop := if b then True else False.
(* subtype of *A* that only interests those who pass the filter *)
Definition subsetA : Set := {a : A | IstrueB (filter a) }.
我试试这个代码铸元件A
到subsetA
时filter
遍,但未能Coq的便利,这是关于“SIG”类型的元素的有效结构:
Definition cast (a: A) : option subsetA :=
match (filter a) with
| true => Some (exist _ a (IstrueB (filter a)))
| false => None
end.
错误:
In environment
a : A
The term "IstrueB (filter a)" has type "Prop"
while it is expected to have type "?P a"
(unable to find a well-typed instantiation for "?P": cannot ensure that
"A -> Type" is a subtype of "[email protected]{__:=a} -> Prop").
所以,勒柯克预计(IstrueB (filter a))
类型的实际证明,但我提供有输入Prop
。
请问您如何提供此类型的灯光?谢谢。
还有'Is_true'在'Bool'。 – eponier