From d4a421e57d74d305a797897f43ce216fb4c39719 Mon Sep 17 00:00:00 2001 From: Matthieu Sozeau Date: Mon, 14 Mar 2016 11:16:19 +0100 Subject: Typeclasses: stdlib fixes for new search algorithm --- theories/Classes/RelationPairs.v | 5 +++++ theories/MSets/MSetInterface.v | 3 +++ theories/Numbers/NatInt/NZGcd.v | 4 +++- theories/Numbers/Rational/SpecViaQ/QSig.v | 10 ++++++++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/theories/Classes/RelationPairs.v b/theories/Classes/RelationPairs.v index cbde5f9ab5..8d1c49822b 100644 --- a/theories/Classes/RelationPairs.v +++ b/theories/Classes/RelationPairs.v @@ -43,6 +43,9 @@ Generalizable Variables A B RA RB Ri Ro f. Definition RelCompFun {A} {B : Type}(R:relation B)(f:A->B) : relation A := fun a a' => R (f a) (f a'). +(** Instances on RelCompFun must match syntactically *) +Typeclasses Opaque RelCompFun. + Infix "@@" := RelCompFun (at level 30, right associativity) : signature_scope. Notation "R @@1" := (R @@ Fst)%signature (at level 30) : signature_scope. @@ -65,6 +68,8 @@ Instance snd_measure : @Measure (A * B) B Snd. Definition RelProd {A : Type} {B : Type} (RA:relation A)(RB:relation B) : relation (A*B) := relation_conjunction (@RelCompFun (A * B) A RA fst) (RB @@2). +Typeclasses Opaque RelProd. + Infix "*" := RelProd : signature_scope. Section RelCompFun_Instances. diff --git a/theories/MSets/MSetInterface.v b/theories/MSets/MSetInterface.v index bd88116899..74a7f6df89 100644 --- a/theories/MSets/MSetInterface.v +++ b/theories/MSets/MSetInterface.v @@ -345,6 +345,9 @@ Module Type WRawSets (E : DecidableType). predicate [Ok]. If [Ok] isn't decidable, [isok] may be the always-false function. *) Parameter isok : t -> bool. + (** MS: + Dangerous instance, the [isok s = true] hypothesis cannot be discharged + with typeclass resolution. Is it really an instance? *) Declare Instance isok_Ok s `(isok s = true) : Ok s | 10. (** Logical predicates *) diff --git a/theories/Numbers/NatInt/NZGcd.v b/theories/Numbers/NatInt/NZGcd.v index 1d36729435..7564c2061d 100644 --- a/theories/Numbers/NatInt/NZGcd.v +++ b/theories/Numbers/NatInt/NZGcd.v @@ -60,7 +60,9 @@ Proof. intros n. exists 0. now nzsimpl. Qed. -Hint Rewrite divide_1_l divide_0_r : nz. +(* MS: These rewrites apply to any subterm of type Z, do not try + them automatically *) +(* Hint Rewrite divide_1_l divide_0_r : nz. *) Lemma divide_0_l : forall n, (0 | n) -> n==0. Proof. diff --git a/theories/Numbers/Rational/SpecViaQ/QSig.v b/theories/Numbers/Rational/SpecViaQ/QSig.v index a40d940598..8e20fd0608 100644 --- a/theories/Numbers/Rational/SpecViaQ/QSig.v +++ b/theories/Numbers/Rational/SpecViaQ/QSig.v @@ -115,7 +115,10 @@ Ltac solve_wd2 := intros x x' Hx y y' Hy; qify; now rewrite Hx, Hy. Local Obligation Tactic := solve_wd2 || solve_wd1. Instance : Measure to_Q. -Instance eq_equiv : Equivalence eq := {}. +Instance eq_equiv : Equivalence eq. +Proof. + change eq with (RelCompFun Qeq to_Q); apply _. +Defined. Program Instance lt_wd : Proper (eq==>eq==>iff) lt. Program Instance le_wd : Proper (eq==>eq==>iff) le. @@ -141,7 +144,10 @@ Proof. intros. qify. destruct (Qcompare_spec [x] [y]); auto. Qed. (** Let's implement [TotalOrder] *) Definition lt_compat := lt_wd. -Instance lt_strorder : StrictOrder lt := {}. +Instance lt_strorder : StrictOrder lt. +Proof. + change lt with (RelCompFun Qlt to_Q); apply _. +Qed. Lemma le_lteq : forall x y, x<=y <-> x