Coq 选项的Ord typeclass实例
在软件基础“QuickChick”第4卷中,我们有以下练习:Coq 选项的Ord typeclass实例,coq,typeclass,logical-foundations,Coq,Typeclass,Logical Foundations,在软件基础“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
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]).
并突出显示将opt1与匹配
- 也许,我的解决方案相当原始:它只是模式匹配所有可能的情况。还有更好的吗
- 是什么导致了这个语法错误
只需在最后一次结束后移除