coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Kevin Hamlen <hamlen AT utdallas.edu>
- To: <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] module "best practices"?
- Date: Sun, 19 Aug 2018 22:53:08 -0500
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=hamlen AT utdallas.edu; spf=Pass smtp.mailfrom=hamlen AT utdallas.edu; spf=None smtp.helo=postmaster AT esa4.hc50-71.r1.ces.cisco.com
- Ironport-phdr: 9a23:32wcQBznXYBfnhbXCy+O+j09IxM/srCxBDY+r6Qd2+kWIJqq85mqBkHD//Il1AaPAd2Fraocw8Pt8InYEVQa5piAtH1QOLdtbDQizfssogo7HcSeAlf6JvO5JwYzHcBFSUM3tyrjaRsdF8nxfUDdrWOv5jAOBBr/KRB1JuPoEYLOksi7ze+/94HSbglSmDaxfa55IQmrownWqsQYm5ZpJLwryhvOrHtIeuBWyn1tKFmOgRvy5dq+8YB6/ShItP0v68BPUaPhf6QlVrNYFygpM3o05MLwqxbOSxaE62YGXWUXlhpIBBXF7A3/U5zsvCb2qvZx1S+HNsDwULs6Wymt771zRRH1likHOT43/mLZhMN+g61Uog6uqRN+w4PPfIGYN+Bzcr/Bcd4UR2dMWNtaWSxbAoO7aosCF+8PMvhGr4n8oVsFsBmwChOpBOPr1DBIgGL90Ko60+s7FAHG2BIvH9QVvXTJsNX6Kb0dUeSxzKbS1jXPde1Z1irg6IXRdB0qvP+CXbV1ccXLyEkvERvIgUuJqYz4JTyV0uUNs3Sa7+V+TuKjkXUnqwZprjiuwMcslpfGhoYPxl/Z6yp0xps+K96gSENjYdOoDoFcui6aOodsXM8vQ3xktDwnxrAFuZO3ZDUGxIg9yxLCaPGLbZKE7xD/WOqLPDt1im5pdKqiixqs9UWs0PDwWtSo3FpQsCZIncfAumoQ2xHc6cWKTOZ28F271jaVzQ/T7/lJIUAqmqrfLJ4s2qA/loEJvknMBCP2mFn5ga+Kekk9+OWk9v7rYq/7qpOGK4B7lBr+Pr4ylcy+GuQ3Lg8OU3KH9uS70b3v5Uz5QLNUgf0qiqTUsI7WKd4Uq6O5GQNZzIYu5wulAzu709kVnWELLFdfdxKGi4jpNUvOIPf9Dfqng1SjijJrx/TYMb3nGZjNM2TDn6r7crZ5705T0hEzwcpB6J1JF7ENOOjzVVPptNzEEh85NBS5zPrgCNVkz48RRWaPArKCP67Jql+J5ucvI/GWa4MPuTb9LeIl5//0gnMjl18dZ/rh4ZxCPHu/B7FtJ1iTSXvqmNYIV2kQ6FkQVuvv3X6PTz9VL1a7WqYx4HlvCIujCYrFbp2xjLWF2C6gWJBaezYVWRi3DX70etDcCL83YyWIL5o5y21WZf2aU4YkkCqWmkr/wrtjIPDT/3RE54//2NFx4+TI0xw+6G4tVpjP4yS2V2hx21gwaXouxqkm/R5g1luK1axxmLpVGcEBv6oUADd/DobVyqlBM/63Wg/FeYzQGlu9S4ngATpsFpdumpkUOgB2Fs7khRHY1C3sCLgQxeSG
Dear Michael,
Thank you for your suggestion; it's enormously helpful. I agree that it's the best solution I've seen.
As you pointed out, the only downside I've found so far is that one must still be very careful about any Module Type that defines/imports a Module (instead of a Module Type). If any names from that Module leak into theorems or ltacs exported by the Module Type, then those theorems and ltacs sometimes aren't recognized by Coq as unifying with differently-named terms created by equivalent but distinct instances of the same Module. But with sufficient care and avoidance of Modules in favor of Module Types, I think your approach works.
To answer your questions: Our use of modules is driven by the need to parameterize our definitions by things that the Coq standard libraries define as modules (e.g., in Coq.Structures.Equalities). So although the module functor that receives one of these library-provided modules need not have a module-type that allows multiple implementations, the module it receives has a module-type and may indeed have various different implementations. This seems to create a domino effect---all module functors in the inheritance hierarchy must apparently be implemented as module-types instead of modules, and all instantiations of those module-types are just dummy modules that include everything from the module-type.
Since we're targeting our project to eventually be open-source and hopefully valuable for general use, we were searching for an approach that is "accepted" by others. This seems like a good one.
Best regards,
Kevin
On 8/19/2018 4:15 AM, Soegtrop, Michael wrote:
Dear Samuel,
I think I have shown how to fix this kind of issue in my post. I don't see
how your case is different. I would suggest to try the following:
- put the inductive type definitions from module functor Imp into a module
type functor IMP
- define module Imp as "Module Imp (P : ImpParameters) := Empty <+ IMP P."
- give everything which needs Imp a parameter of type IMP and instantiate it
with Imp
- possibly define combined module types and modules to avoid long parameter
lists
The trick is that now the inductive definition is in the module type rather
than in the module instance and the type is the same for all instances, so
the inductive types are the same. At the end of the code I posted, you can
actually prove the following:
Theorem Eq1: FD.bar = FDX.bar.
Proof.
reflexivity.
Qed.
Theorem Eq2: FD.Bar = FDX.Bar.
Proof.
reflexivity.
Qed.
although Coq still thinks FD.bar and FDX.bar are separate definitions as
Locate bar or Locate Bar shows.
This might seem like a bizarre hack, but I think it is quite logical to do it
this way. My view is that whatever is needed by other modules must be defined
in a module type. Modules are there to define concrete implementations of
abstract definitions in a module type. Other modules should only use module
types and not concrete modules. When you cannot abstract away from what is in
a module, it is part of the interface and doesn't belong in a module but in a
module type.
If you have an inductive definition and where you use this type you can
replace it with an abstract type (say a generic map data structure), the
inductive belongs in a module and the module type just provides an abstract
type. If you need the details of the inductive in modules using it, the
inductive belongs into a module type.
Of cause if a module A just uses another module B to implement its
functionality in such a way that nothing of B is visible at the interface
(signature) of A, A can just use a module B. This typically applies to
modules just defining a bunch of lemmas, tactics or notations but also to
modules defining helper data structures like maps or sets, which are
abstracted away at the external interface of module A. But anything about
other modules which is somehow visible in the signature of A, must be defined
in a module type, and not in a module.
In my experience the module system works quite well, if it is used in this
way.
I hope those who came up with the module system agree with this view.
Best regards,
Michael
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
- [Coq-Club] module "best practices"?, Kevin Hamlen, 08/17/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/18/2018
- Re: [Coq-Club] module "best practices"?, Samuel Gruetter, 08/18/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/19/2018
- Re: [Coq-Club] module "best practices"?, Kevin Hamlen, 08/20/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/20/2018
- Re: [Coq-Club] module "best practices"?, Benjamin C. Pierce, 08/20/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/23/2018
- Re: [Coq-Club] module "best practices"?, Benjamin C. Pierce, 08/20/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/20/2018
- Re: [Coq-Club] module "best practices"?, Kevin Hamlen, 08/20/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/19/2018
- Re: [Coq-Club] module "best practices"?, Adam Chlipala, 08/21/2018
- Re: [Coq-Club] module "best practices"?, Kevin Hamlen, 08/21/2018
- Re: [Coq-Club] module "best practices"?, Samuel Gruetter, 08/22/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/23/2018
- Re: [Coq-Club] module "best practices"?, David Holland, 08/23/2018
- Re: [Coq-Club] module "best practices"?, Anders Lundstedt, 08/24/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/24/2018
- Re: [Coq-Club] module "best practices"?, Anders Lundstedt, 08/24/2018
- Re: [Coq-Club] module "best practices"?, David Holland, 08/23/2018
- RE: [Coq-Club] module "best practices"?, Soegtrop, Michael, 08/23/2018
- Re: [Coq-Club] module "best practices"?, Samuel Gruetter, 08/22/2018
- Re: [Coq-Club] module "best practices"?, Kevin Hamlen, 08/21/2018
Archive powered by MHonArc 2.6.18.