首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选项Ord typeclass实例

选项Ord typeclass实例
EN

Stack Overflow用户
提问于 2020-08-06 21:11:40
回答 1查看 39关注 0票数 0

在软件基础"QuickChick“的第4卷中,我们有以下摘录:

代码语言:javascript
复制
Class Ord A `{Eq A} : Type :=
{
    le : A -> A -> bool
}.

(* Define [Ord] instances for options and pairs. *)
(* So I am trying to do it *)

Instance optionOrd {A : Type} `{Ord A} `{Eq (option A)} : Ord (option A) :=
{
  le := fun (opt1 opt2 : option A) =>
          match opt1 with
          | None => match opt2 with
                   | None => true
                   | Some a => true
                   end
          | Some a1 => match opt2 with
                      | None => false
                      | Some a2 => le a1 a2
                      end
          end.
}.

但是得到一个错误:

代码语言:javascript
复制
Error: Syntax error: '}' expected after [constr:record_declaration]
 (in [vernac:gallina_ext]).

它突出了match opt1 with

  • 可能是,我的解决方案非常原始:它只是模式匹配所有可能的情况。还有更好的吗?

  • 是什么导致了这个语法错误?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-06 22:07:20

只需在上一次.之后删除end

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

https://stackoverflow.com/questions/63291803

复制
相关文章

相似问题

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