coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Robbert Krebbers <mailinglists AT robbertkrebbers.nl>
- To: coq-club <coq-club AT inria.fr>
- Subject: [Coq-Club] Module Include leads to duplicate type class instances
- Date: Tue, 13 Dec 2016 09:22:10 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mailinglists AT robbertkrebbers.nl; spf=None smtp.mailfrom=mailinglists AT robbertkrebbers.nl; spf=None smtp.helo=postmaster AT smtp1.science.ru.nl
- Ironport-phdr: 9a23:JywtEhenAIhZbL9+7Ju92JdElGMj4u6mDksu8pMizoh2WeGdxc67ZR7h7PlgxGXEQZ/co6odzbGH6Oa+AiddvN7B6ClEK8McEUddyI0/pE8JPo2sMQXDNvnkbig3ToxpdWRO2DWFC3VTA9v0fFbIo3e/vnY4ExT7MhdpdKyuQtaBx/KejL/pvsWPK0UV3HvuKY91eR6xtEDastQcyd9pLb90wR/UqFNJff5XzCVmPwTAsQz745KK+5Rp/j5M89E7+sRKXL/hN/A9RL1cDTIpN2Eu+NbDrx7JRwaV+ngGX28cnwBTRQ7BukKpFqztuzf347IukBKROtf7GO1sVA==
Hi Coq-club,
We noticed that Including a module leads to all type class instances being redeclared. In the example below this will make type class search backtrack on foo.c_and and bar.c_and for each subterm, and thereby turning a search that takes linear time into a search that takes exponential time.
Is it a feature or a bug that type class instances are being redeclared when a module is included?
Does someone know a workaround for the problem? Some solutions that we came up with:
- We could just not declare instances in the module `foo`, but
instead use `Existing Instances` in `bar`. [In our actual code we have about 100 such instances in `foo`, so this does not really scale.]
- We could `Export` foo in bar instead of including it, but that makes it impossible to refer to lemmas lem in foo as bar.lem. [In our actual code, we are using modules this way to include several modules `foo1`, `foo2` and `foo3` into one module `bar` so as to be able to refer to lemmas in `foo1`, `foo2` and `foo3` through one common namespace `bar`).
Best,
Robbert
* Thanks to JH Jourdan for finding this problem in our actual code: https://gitlab.mpi-sws.org/FP/iris-coq/blob/master/theories/base_logic/base_logic.v
---------------
Class C (P : Prop) := { }.
Module foo.
Instance c_true : C True.
Instance c_and P Q : C P -> C Q -> C (P /\ Q).
End foo.
Module bar.
Include foo.
End bar.
Goal C (True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ True /\ False).
Typeclasses eauto := debug.
Time try apply _. (* 2.148s *)
- [Coq-Club] Module Include leads to duplicate type class instances, Robbert Krebbers, 12/13/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Jason Gross, 12/13/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Robbert Krebbers, 12/13/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Ralf Jung, 12/15/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Guillaume Melquiond, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Jason Gross, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Ralf Jung, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Jason Gross, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Guillaume Melquiond, 12/17/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Ralf Jung, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Jason Gross, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Guillaume Melquiond, 12/16/2016
- Re: [Coq-Club] Module Include leads to duplicate type class instances, Jason Gross, 12/13/2016
Archive powered by MHonArc 2.6.18.