首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Coq:“`PartialOrder` ` typeclass”的用法

Coq:“`PartialOrder` ` typeclass”的用法
EN

Stack Overflow用户
提问于 2017-06-18 01:38:10
回答 1查看 112关注 0票数 1

我试图在偏序集上定义字符串上的字典顺序,但我不完全确定如何使用PartialOrder类型集。

代码语言:javascript
复制
Require Import List RelationClasses.

Fail Inductive lex_leq {A : Type} `{po : PartialOrder A} : list A -> list A -> Prop :=
  | lnil: forall l, lex_leq nil l
  | lcons: 
      forall (hd1 hd2 : A) (tl1 tl2 : list A),
        hd1 <= hd2 -> (* error *)
        (hd1 = hd2 -> lex_leq tl1 tl2) -> 
        lex_leq (hd1 :: tl1) (hd2 :: tl2).

部分产出:

代码语言:javascript
复制
The term "hd1" has type "A" while it is expected to have type "nat".

显然,在这里使用<=是错误的;我想知道如何从我的po实例中获得排序关系。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-18 08:32:03

我们可以显式地绑定名称以使事情变得更加明显。在完成此操作之前,我们需要告诉Coq不要使用Generalizable Variables命令抱怨未绑定的变量:

代码语言:javascript
复制
From Coq Require Import List RelationClasses.

Generalizable Variables A eqA R.

Inductive lex_leq `{PartialOrder A eqA R} : list A -> list A -> Prop :=
  | lnil: forall l, lex_leq nil l
  | lcons: 
      forall (hd1 hd2 : A) (tl1 tl2 : list A),
        R hd1 hd2 ->
        (hd1 = hd2 -> lex_leq tl1 tl2) -> 
        lex_leq (hd1 :: tl1) (hd2 :: tl2).

您可以在手册(这里)中找到更多信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44610998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档