选项的 Ord 类型类实例

Instance of Ord typeclass for option

在软件基础“QuickChick”的第 4 卷中,我们有以下练习:

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.
}.

但是报错:

Error: Syntax error: '}' expected after [constr:record_declaration]
 (in [vernac:gallina_ext]).

并突出显示 match opt1 with

只需删除最后一个 end 之后的 .