Types 辅酶Q亚型多态性
我想定义一个带变量扇出的加权树,它在类型上是多态的。我想到了这个:Types 辅酶Q亚型多态性,types,polymorphism,coq,Types,Polymorphism,Coq,我想定义一个带变量扇出的加权树,它在类型上是多态的。我想到了这个: (* Weighted tree with topological ordering on the nodes. *) Inductive wtree (A : Type) : Type := LNode : A->wtree A | INode : A->list (R*wtree A) -> wtree A. 但是,我更喜欢将重量存储在类型中,例如: Inductive Wtype (A : Type
(* Weighted tree with topological ordering on the nodes. *)
Inductive wtree (A : Type) : Type :=
LNode : A->wtree A
| INode : A->list (R*wtree A) -> wtree A.
但是,我更喜欢将重量存储在类型中,例如:
Inductive Wtype (A : Type) : Type := W : R->A->Wtype A.
Inductive wtree (A : Wtype) : Type :=
LNode : A->wtree A
| INode : A->list (wtree A) -> wtree A.
其中R
是标准库中的实数集
这不起作用,因为
Wtype
是Type->Type
,而不是Type
,但我不知道怎么做。不幸的是,我仍然生活在面向对象的世界里,我真的只想给a
一个比type
更严格的超级类型,但就是不知道如何在Coq中实现它 我想我已经解决了这个问题:
Inductive Wtype (A : Type) : Type := W : R->A->Wtype A.
Inductive wtree (A : Type) : Type :=
LNode : Wtype A->wtree A
| INode : Wtype A->list (wtree A) -> wtree A.
然而,如果能说一些更像是
归纳wtree(A:WType)…
的话,并避免在整个定义中使用大量的“wtypea
”来混淆定义,那就更好了 问题是Wtype
是Type->Type
是吗?既然我们不能应用它,我们需要给它一些论证。所以我们需要把它应用到一些论点中。一个简单的解决方案可能是
Inductive wtree' (A : Type) : Type :=
| LNode : A -> wtree' A
| INode : A -> list (wtree' A) -> wtree A.
Inductive Wtype (A : Type) : Type := W : R -> A -> Wtype A.
Definition wtree (A : Type) := wtree' (Wtype A).