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: Ralf Jung <jung AT mpi-sws.org>
  • To: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Opaque module typing with exposing function defs
  • Date: Thu, 27 Apr 2017 09:25:29 +0200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=jung AT mpi-sws.org; spf=Pass smtp.mailfrom=jung AT mpi-sws.org; spf=None smtp.helo=postmaster AT juno.mpi-klsb.mpg.de
  • Ironport-phdr: 9a23:lgSX8xbcqM5vbGDvpxu5vxD/LSx+4OfEezUN459isYplN5qZocmybnLW6fgltlLVR4KTs6sC0LuK9fi4EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQtFiT6ybL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPCTQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD0fOjAk7m/XhMx+gqFVrh2vqBNwwZLbbo6OOfpifa7QZ88WSXZPU8tTUSFKH4Oyb5EID+oEJetWs5Pyp18ArRCjAQesGeXvyjBVjXLx3606zuIhEQ7d0QwlB9IOsW3YrM77NacJS+y1y7PIzTraYv5QxDzz65DIfwg8rfyCWb98a9fdxE01Gw7Gj1ics4PoMjyT2+8QqWaU9fBgWviqi2M/qwF+vDyvxsA0h4nLm4IVzFfE+T98wIYtJN20UU17Ydq/EJRLrS2aMpN2Qsw4T251pik20rwGuZilcygW0Jkr2hDSZvidf4SV5h/vTuWcLDZiiH9qd7+znxOy/lKhyu34WMm0ylFKri9dn9nOq3AN0RPT59OCSvtl/0etwC2P1g7I6u1eJkA0j6XbJ4Y7wrEsjpoTrVjDHijulUrqi6+Wb1wo9fSs6+T6ebrrvYScNo9xigHmKKsigM2/AeIiMggPRWeX4+q81KewtXH+Fb5Nl7g9lrTTmJHcP8US4KCjUCFP1YN20R+7AX+EzdIX1S0FMVRKUBefjs3yJEqIJ+r3W6Tsy2+wmStmkqiVdobqBY/AeyDO

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