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: Pierre Courtieu <pierre.courtieu AT gmail.com>
  • To: Coq Club <coq-club AT inria.fr>
  • Subject: Re: [Coq-Club] Opaque module typing with exposing function defs
  • Date: Thu, 27 Apr 2017 18:34:45 +0200
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=pierre.courtieu AT gmail.com; spf=Pass smtp.mailfrom=pierre.courtieu AT gmail.com; spf=None smtp.helo=postmaster AT mail-wm0-f42.google.com
  • Ironport-phdr: 9a23:jGVZUxRI55JtlTR6NwhjKXgui9psv+yvbD5Q0YIujvd0So/mwa6yZB2N2/xhgRfzUJnB7Loc0qyN4vymATRIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSijewZbx/IA+qoQnNq8IbnZZsJqEtxxXTv3BGYf5WxWRmJVKSmxbz+MK994N9/ipTpvws6ddOXb31cKokQ7NYCi8mM30u683wqRbDVwqP6WACXWgQjxFFHhLK7BD+Xpf2ryv6qu9w0zSUMMHqUbw5Xymp4rx1QxH0ligIKz858HnWisNuiqJbvAmhrAF7z4LNfY2ZKOZycqbbcNgHR2ROQ9xRWjRDDYOyb4UBAekPM/tGoYbhqFUDtge+BRC2Ce/z1jNEmn370Ksn2OohCwHG2wkgEsoUvnTVstr1Lr0SXv6ox6TWyjXDculW2Sv86IfWbxAqvPaBXapxccXP00kvDR3Kgk+MpoziIjOVzPgNs2mF4Op9Tu+vhGsnpBtwojir3Msjlo7JhocMx13C6C53zoE1JdiiR056Z96pCJpQtyeAN4t3WMwuWW9ouDw8x7YbupC7ZDAHxZYoyhLFdvCLbYiF7gjgWeqPOzt1i2xpdbSijBio60eg0PfzVsys3VZKsCVFlt7Mu2gI1xPJ68iHTuJx/0mk2TqTzgzT5O5JLV4umarULJ4hxbEwlp4NvkjZAiD2n0D2gLeXdkUi5Oeo9/zqb7fpq5OGKoN4lAHzPr4tl8ChG+g1PRYCU3Ce+eum1b3j+UP5QK9Njv0ziqTZqJHaKtoBpq6jHQBZyJos6xGiDze8zNQYnGcILE9edRKIiojmIVDOIPTiAfijhFSslS9nx+raMb35HpXNMn/Dna/9crZ68k5Q0RY8zdRC551PEbwBO/LyWkrptNPCFBM5Mgq0w/zmCNpnzI8eV3iPUeelN/b5tkbAzeYyKaHYb4gM/T35NvIN5vj0jHZ/l0VLLoez2p5CUHG1BO5ra26efGDwg9ocWTMSvwckVuGsg1qfSyJSamuaUKc15zV9A4WjW9SQDruxiaCMiX/oVqZdYXpLXxXVSS/l

2017-04-27 17:40 GMT+02:00 Julia Belyakova
<julbinb AT gmail.com>:
> Jason, Gaëtan,
>
> Thank you for replies!
>
> Local definitions are still available through qualified names. And I would
> like to hide them completely.
>
> My motivation is as follows: I want to provide a module with some datatypes,
> functions, and theorems about them. To implement those functions and prove
> theorems, I use many auxiliary functions and lemmas, which are of no utility
> for the user of the module.

Hiding the definitions makes computation with these functions
impossible. So this is not what you are looking for.

If it is really important to hide these functions to the user you can
do the following:

1) Define a module type T with definitions hidden

Module Type T.
Variable f: ...
End T.

2) Start the module definition with

Module Foo<:T.
Definition t :=....
End T.

At this moment Foo.f is visible. Now you can hide it if you start a
new functor taking a T as argument instead of using Foo explicitely.

Modul Bar (F:T).
(* F.f is hidden. *)
...
End Bar.

Now if you want to have an instance of Bar you can do

Module B := Bar(Foo).

The problem with this approach is that each time you want to hide f
you need to start a functor. You generally end up with functors
everywhere. You should balance the pros and cons of simply showing the
auxiliary functions to the user.

Class types are generally considered an alternative to modules but I
don't know if there is a hiding mechanism.

Hope this helps,
Pierre






This is generally not true that function definition (even auxiliary
ones) are of no use for the user. Coq has dependent types, which means
that typing needs to compute with these functions (to check
convertibility).



You may hide Lemmas because there is no reason the typer will need to
reduce in there body (except lemmas used in well founded proofs used
in recursive functions). But you can't hide function definitions most
of the time because




> So I want to keep an interface of the module clean and concise. For example,
> when the module is printed, I don't want it to show all the aux stuff.
>
> Opaque typing is ok for hiding aux lemmas, because I still can use (apply)
> main theorems to prove something outside of the module. But what hits me is
> that it's not possible to use functions. The module becomes totally useless.
>
> In the worst case I will simply put all the aux stuff into a submodule, so
> that an interface of the main module does not look dirty.
>
> --
> Kind regards, Julia
>
> чт, 27 апр. 2017 г. в 11:12, Gaetan Gilbert
> <gaetan.gilbert AT ens-lyon.fr>:
>>
>> What do you mean by hiding? Is "Local Definition"/"Local Lemma" enough?
>>
>> (https://coq.inria.fr/distrib/current/refman/Reference-Manual003.html#hevea_command10)
>>
>> Gaëtan Gilbert
>>
>> 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.
>> >
>> > 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