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:46:08 +0000
  • Authentication-results: mail3-smtp-sop.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-qt0-f175.google.com
  • Ironport-phdr: 9a23:FDAvRh3lH1t2aljAsmDT+DRfVm0co7zxezQtwd8Zse0WK/ad9pjvdHbS+e9qxAeQG96Kt7Qc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q89pDXbAhEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7S60/Vza/4KdxUBLnhykHODw5/m/ZicJ+kbxVrw66qhNl34LZepuYOOZicq7fe94RWGpPXtxWVyxEGo6ya5EAD/EGPeZesoLzpkEOrRylBQm3GejizT1IiWXt3a091eQhHhvG3As7H9IVtHnZt9r1NKIIXuC0yKnE1ynMb/RT2Trk7oXDbxMvoemUUL5ubcbczVMjGgDFg1mKt4DpIjKY2v4Qv2WZ7+dtU/+khXQ9pAFruDevw98hionXiYIRzVDJ7SB5z5w0Jd28UUJ7eMKkHIdJuyGUKod7QMMvT3tnuCY9zb0Gtpq7czYQxJs7wB7fbuSLc4mO4h39SOacOSl0iG5hdb6lhBu/8VKsxvPhWsS1ylpGsyhIn9nUunAIzRPT68yHSvVn/kem3DaCzwLT5ftfIUAzk6rbJIQhwrkrlpoItUnOBSD2mEDsg6+XckUo4PSn6+PiYrn+vJ+TK5d0ih3iMqQpgsGwHeM4MhEXU2eH/eS8yabs8FbiQLRKi/02irPWvIrbJcQdvK65AhVa3pwt6xalXH+a14ETmmBCJ1ZYcjqGiZLoMhfAOqPWF/C61nalizBtj9/cOab6SsHPJ2PElrj7eq1mumZTzQMyyZZU4JcCWeJJG+76RkKk7I+QNRQ+KQHhm+s=

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