Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Preventing pollution of typeclass resolution when Require Importing a MathClasses module

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Preventing pollution of typeclass resolution when Require Importing a MathClasses module


Chronological Thread 
  • From: Yannick Zakowski <zakowski AT seas.upenn.edu>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Preventing pollution of typeclass resolution when Require Importing a MathClasses module
  • Date: Thu, 16 Jul 2020 09:45:19 -0400
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=zakowski AT seas.upenn.edu; spf=Pass smtp.mailfrom=zakowski AT seas.upenn.edu; spf=None smtp.helo=postmaster AT mail-qk1-f176.google.com
  • Ironport-phdr: 9a23:I0ZFkROuOOvck/juF1Al6mtUPXoX/o7sNwtQ0KIMzox0Ivn4rarrMEGX3/hxlliBBdydt6sazbGK+P67EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe8bL9oIhi7ogrdu8gYjIB/Nqs/1xzFr2dSde9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLYTQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVRnlgzoFOTEk6mHaktF+grxVoByhpBJxzYDbb46XO/ViZa7SZ88WSHBbU8pNWSFMAIWxZJYPAeobOuZYqpHwqFkUohu4AwmsBf/gyjxVjXD1x6I60OMhEA/d3AwjHtIFrXPZrdTvO6cRVuC0wrLIzTbCb/5Nwjfy9pLHcgs7rfGRRbJ/b8zRyU81Gwzbk1qQtJXoMjWI3esCr2aV9fBvVf6zi2E5sQFxpCCiy9swh4TNmI4Y107J+CV5zog7JdO1R1N2bNyrHZVeuCyXNJV7T8EmTm10tis0xaMKtJGmcCUE1pgq2RrSZviaf4WO/xntV/6RLC9miH55fL+znRW//Ei6xuHiSMW4zkxGojdHn9TNrnwA1hje5tKZRvZ98EqtwyiD2xzP5u1eIE05m6zWIIM7zLEqjJocq0HDEzf2mEroiK+WcV0p+u2y5OTmZrXqv4acN4xphg3nPKQih86yDOUiPggBWGib/uu81Ln98kHjXLpKifg2nrHYsJDcO8sbura0DxFJ3osn8RqyDDer3M4GkXUZMl5JYg+LgoroNl3WJfD3F/a/g1CikDdxwPDGO6XsA5TXIXjAl7fgc619601dyAco1tBQ+YhbCqobLPLuQk/+qtrYDhkjPwOq3unnFc1x1pkCVmKXHq+ZLKTSvEeU6eIoOumAfZMauDLgK/c+/PPuln84mVoFfaazx5cXaXa4Hu5nI0qDe3bsjM0BQi82uV81S/Wvg1mfWxZSYWyzVuQy/GIVEoWjWLbKQIasi7/J7i64GYJNZWEOXkKFEnD3bIaFc+wBYTnUP9dslDpCWLS8HdxynSqyvRP3nuI0ZtHf/TcV4Mq6iYpFotbLnBR3zgRaSsSQ12bXETNxl2IMAiY1heVx+BMjjFiE1qd8jrpTEtkBv6oYADd/DobVyqlBM/63XwvAetmTT1P/HIe9DDgqCM8pztkIJUtxBof710yR72+RG7YQ0oezKtks6KuFgSrqKs9mjWve2a8nyVQqX5kXOA==

Hello,

That's a sensible suggestion, unfortunately I do not quite understand why this hint gets applied. In the minimal example from my original message, the beginning of the debug trace goes as follows:

Debug: 1: looking for (Proper (rel ==> ?r) op) with backtracking
Debug: 1.1: exact rel_op_Proper on (Proper (rel ==> ?r) op), 0 subgoal(s)
Debug: 2: looking for (Proper (rel ==> ?r ==> flip impl) rel) with backtracking
Debug: 2.1: simple apply @sm_proper on (Proper (rel ==> ?r ==> flip impl) rel), 1 subgoal(s)
Debug: 2.1-1 : (Setoid_Morphism rel)

We are looking for a Proper instance as expected, nothing in this goal explicitly refers to equiv (i.e. "=" from MathClasses perspective), and yet `sm_proper` gets applied.

Yannick

On 7/16/20 6:23 AM, Matthieu Sozeau wrote:
Dear Yannick,

Le 15 juil. 2020 à 16:32, Yannick Zakowski <zakowski AT seas.upenn.edu> a écrit :

Dear all,

Consider the following self-contained example:

From Coq Require Import
     Setoid
     Morphisms
     RelationClasses.

Section Foo.

  Variable op: nat -> nat.

  Variable rel: nat -> nat -> Prop.

  Context {rel_op_Proper: (Proper (rel ==> rel) op)}.
  Context {rel_trans: Transitive rel}.

  Goal forall (a b: nat) (REL: rel a b),
      rel (op a) (op b).
  Proof.
    intros.
    Typeclasses eauto := debug.
    rewrite REL.
    (* Resolution in 6 steps *)
    Undo.
    Require Import MathClasses.interfaces.abstract_algebra.
    rewrite REL.
    (* Resolution in over 100 steps *)
  Abort.

End Foo.

I am looking for a way to avoid this side-effect of loading this MathClass module.
The problem touches to the overall issues of Hints being aggressively exported, and instances all sharing a single namespace. A general solution would naturally be welcome, but I would already be very happy with a hacky local solution allowing me to get back into my proof. In this specific case, it indeed looks to me like the main culprit that gets applied early and completely derail the proof search is the following External Hint declared in `abstract_algebra.v`:

Hint Extern 4 (?f _ = ?f _) => unshelve eapply (sm_proper (f:=f)).

I have given a shot at `Set Loose Hint Behavior "Strict".` without success. For good conscience I also tried `Remove Hints sm_proper: core_db.`, but as described in the documentation, it does not apply to External Hints.

Any idea as to how to solve this problem would help me a great deal.
I don’t see a way to avoid the import of instances from math-classes if you have to Require Import. 
However, the shape of the hint here might leave some hope for finding a workaround, because generalized
rewriting itself does not generate `(_ = _)` subgoals to be solved by type class resolution, only
`Proper R f`, `ProperProxy R f` and `subrelation R R’` goals. So you might have more luck disabling
the hint that produces the `(_ = _)` subgoal?

Best,
— Matthieu



Archive powered by MHonArc 2.6.19+.

Top of Page