Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Opaque module typing with exposing function defs

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Opaque module typing with exposing function defs


Chronological Thread 
  • From: Jason Gross <jasongross9 AT gmail.com>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Opaque module typing with exposing function defs
  • Date: Thu, 27 Apr 2017 14:53:00 +0000
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=jasongross9 AT gmail.com; spf=Pass smtp.mailfrom=jasongross9 AT gmail.com; spf=None smtp.helo=postmaster AT mail-qk0-f174.google.com
  • Ironport-phdr: 9a23:/I+GCxWWE/YalcwMEXYZdTxUF7PV8LGtZVwlr6E/grcLSJyIuqrYYxSGt8tkgFKBZ4jH8fUM07OQ6PG8HzRYqb+681k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRoLerpBIHSk9631+ev8JHPfglEnjSwbLd9IRmssQndqtQdjJd/JKo21hbHuGZDdf5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXMTRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KptVRTmijoINyQh/W7YhMx/jqJVrhyiqRJi3YDbfJqYO+Bicq7HZ94WWXZNU8RXWidcAo28dYwPD+8ZMOhctYb9vFwOrR2jDgetHuPvzSRIhmTr1qA90eQuCxrG3AsmH9IBqnTUq871NLwWXO2uw6nIyC/Mb/JS2Tvn9IfIdRUhrOiKULltcsTR0VEiGx3ZgliUs4DoPDOY2v4Tv2SF8+ZsT/+jhmwopgx3vzOh3N0jipPTiYIQ0l3E9Tt2wIIyJdCgTU50e9+kEJ9JuyGDNIt6XtouQ291tCs4xbAKo5G7fC8NyJQowx7QdeaLfJSP4hLmTOqRIDF4i2x5eL+nmRq+7Uytxvf/W8S0ylpGsDRJnsXWunwQ1RHe5dCLSv5n8Ueg3TaP2RrT6uZBIU0sl6rUMYUhwrk2lpocq0TDGTT2mF7ygaKNeUUk//Kn6+XjYrn8upCcMIp0hhnkMqsygsy/Hfg4Mg8WUmeH/uS8zaTv8lH9QLVXlfI7ibLZsZDfJcQDvKG1GQ5V0oA56xa+FTiqytoYnWNUZG5CLRmAls3iP0zECPH+F/a2xVq2wxlxwPWTHLT6BZOFAWLEi6ypKbR08ElaxxA01ssOz51RA7AFZvn0Xxmi55TjEhYlPlnskK7cA9Jn29ZGVA==

Another possibility is to use sections and [Let], so your private definitions are inlined in your public ones:

Module Type Addition.
  Parameter t : Type.
  Parameter add : t -> t -> t.
End Addition.

Module MAddition <: Addition.
  Section maddition.
    Definition t := nat.
    Definition add x y := x + y.     (* I want this to be available *)
    Let priv_id (x : t) := x. (* This must be hidden *)
  End maddition.
End MAddition.


On Thu, Apr 27, 2017, 10:49 AM Jason Gross <jasongross9 AT gmail.com> wrote:

Note that truly hiding private definitions which are used to define public transparent ones would break subject reduction, and is impossible; it would mean that you could unfold a well-typed identifier and get a term which is invalid.


On Thu, Apr 27, 2017, 10:46 AM Jason Gross <jasongross9 AT gmail.com> wrote:

Does this do what you want?

Module Type Addition.
  Parameter t : Type.
  Parameter add : t -> t -> t.
End Addition.

Module MAddition <: Addition.


  Definition t := nat.
  Definition add x y := x + y.     (* I want this to be available *)

  Local Definition priv_id (x : t) := x. (* This must be hidden *)
End MAddition.


On Thu, Apr 27, 2017, 7:45 AM Julia Belyakova <julbinb AT gmail.com> wrote:
Hello Ralf,

I use an aux private function to implement a public one, so this solution does not work in this case.

--
Kind regards, Julia

чт, 27 апр. 2017 г., 3:25 Ralf Jung <jung AT mpi-sws.org>:
Hi,

On 27.04.2017 03:03, Julia Belyakova wrote:
> Thank you for reply!
>
> Are there other ways to hide some parts of a module except for opaque
> typing? I am primarily interested in hiding auxiliary lemmas.

Doesn't the following, proposed in the previous mail by Istvan, do
exactly that?

> Module MAddition : Addition
>     with Definition t := nat
>     with Definition add := fun x y => x + y.
>   Definition t := nat.
>   Definition add x y := x + y.
>   Definition priv_id (x : t) := x.
> End MAddition.

Of course, the annoying part is that addition is defined twice.  This is
something I have also encountered when I do hiding via modules:  Many of
the things that *are* exported have to be duplicated.

; Ralf

>
> It seems to me strange though that one cannot actually _use_ functions
> from the opaque-typed module.
>
> --
> Kind regards,
> Julia
>
>
> ср, 26 апр. 2017 г., 17:10 ikdc <ikdc AT mit.edu <mailto:ikdc AT mit.edu>>:
>
>     On 04/26/2017 04:57 PM, Julia Belyakova wrote:
>     > Dear Coq users,
>     >
>     > I guess it's a stupid question, but...
>     >
>     > I want to define a module with certain parts being hidden. For this I
>     > define a module type and then use opaque typing for the module.
>     And the
>     > problem is that now I cannot compute functions of the module, their
>     > definitions are not accessible.
>     >
>     > Please, find a simple example below.
>     >
>     > Module Type Addition.
>     >   Parameter t : Type.
>     >   Parameter add : t -> t -> t.
>     > End Addition.
>     >
>     > Module MAddition : Addition with Definition t := nat.
>     >   Definition t := nat.
>     >   Definition add x y := x + y.     (* I want this to be available *)
>     >   Definition priv_id (x : t) := x. (* This must be hidden *)
>     > End MAddition.
>     >
>     > (* priv_id is not available as desired *)
>     > (* Compute (MAddition.priv_id 4). *)
>     > (* add is available, but the call does not reduce to 7 *)
>     > Compute (MAddition.add 3 4).
>     >
>
>
>     If I understand correctly, I don't think you can do this.  The fact that
>     the module type is opaque means that any program which uses a module
>     with that type must behave the same way; in particular it may not unfold
>     the definitions hidden by the module type.  You could of course do this:
>
>
>     Module MAddition : Addition
>          with Definition t := nat
>          with Definition add := fun x y => x + y.
>        Definition t := nat.
>        Definition add x y := x + y.
>        Definition priv_id (x : t) := x.
>     End MAddition.
>
>
>     But if you want to be able to compute through [add], then perhaps the
>     module type "Addition" isn't actually the interface you want to be using
>     in the first place.
>
>     I don't know very much about the module system, so someone please
>     correct me if this is wrong.
>
>     --
>     Istvan Chung
>



Archive powered by MHonArc 2.6.18.

Top of Page