caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David House <dhouse@janestreet.com>
To: Tiphaine Turpin <Tiphaine.Turpin@free.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] module alias in a .mli file
Date: Mon, 19 Nov 2012 14:51:20 +0000	[thread overview]
Message-ID: <CAK=fH+jh3zhwRZ58VVj2Bm16dEhx-fSsa1z8ifLNh_x5mDjrCw@mail.gmail.com> (raw)
In-Reply-To: <50AA5462.9090201@free.fr>

Very clever! I had always been doing the following to re-establish the
type equality:

  module V3 : module type of Vector3
    with type t = Vector3.t
    with type Submodule.t = Vector3.Submodule.t
    ... etc

But again: this is not a true alias. It actually defines and exposes a
V3 module as a submodule of your module. E.g. if you're talking about
foo.mli then other people would be able to say Foo.V3.

On Mon, Nov 19, 2012 at 3:46 PM, Tiphaine Turpin
<Tiphaine.Turpin@free.fr> wrote:
> In fact, the solution
>
>
>   module V3 : module type of Vector3
>
> does not work completely, because, the equality between Vector3 and V3 is
> lost, which poses problem with the types defined by Vector 3. What works is:
>
>   include module type of struct module V3 = Vector3 end
>
> Here is a full example:
>
> module M : sig
>
>   module Vector3 : sig type t end
>   (* module V3 : module type of Vector3 *)
>   include module type of struct module V3 = Vector3 end
>
> end = struct
>
>   module Vector3 = struct type t end
>   module V3 = Vector3
>
> end
>
> open M
> let id (x : Vector3.t) : V3.t = x
>
>
> Regards,
>
> Tiphaine
>
>
>
> On 11/19/12 13:44, Paolo Donadeo wrote:
>
> Actually this is not true, Martin explained how. :-)
>
>
> --
> Paolo
> Sent by Gmail from Android
>
> Il giorno 19/nov/2012 11:35, "David House" <dhouse@janestreet.com> ha
> scritto:
>>
>> Annoyingly though, there is no way to create a module alias in an mli.
>>
>> If, in an ml file, you have to refer often to
>> Some_very_long_module_name, it can quite convenient to define an alias
>> by doing "module Mod = Some_very_long_module_name" (or, locally, "let
>> module Mod = Some_very_long_module_name in"). But there is no way of
>> doing this in an mli: you have to use the long name every time.
>>
>> This is especially annoying if you have some big type that you want to
>> expose in the mli. You really just want to copy-paste out of the ml
>> file and stick it into the mli, but then you have to expand all the
>> module aliases. (It's just a couple of goes with M-%, but still...)
>>
>> On Mon, Nov 19, 2012 at 6:36 AM, Francois Berenger <berenger@riken.jp>
>> wrote:
>> > On 11/19/2012 03:02 PM, Martin Jambon wrote:
>> >>
>> >> On Sun 18 Nov 2012 09:29:31 PM PST, Francois Berenger wrote:
>> >>>
>> >>> Hello,
>> >>>
>> >>> Here is my stupid question of the day:
>> >>> can't I declare the following in a .mli file?
>> >>>
>> >>> module V3 = Vector3
>> >>
>> >>
>> >> No, because "= Vector3" specifies an implementation.
>> >> An mli file is a module interface, and module interfaces never contain
>> >> implementations.
>> >>
>> >> However, you may want to do this, which does what it says:
>> >>
>> >>   module V3 : module type of Vector3
>> >
>> >
>> > Thanks a lot! That's exactly what I needed. :)
>> >
>> >
>> >
>> >
>> > --
>> > Caml-list mailing list.  Subscription management and archives:
>> > https://sympa.inria.fr/sympa/arc/caml-list
>> > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> > Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>> --
>> Caml-list mailing list.  Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

  reply	other threads:[~2012-11-19 14:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  5:29 Francois Berenger
2012-11-19  6:02 ` Martin Jambon
2012-11-19  6:36   ` Francois Berenger
2012-11-19 10:35     ` David House
2012-11-19 12:44       ` Paolo Donadeo
2012-11-19 15:46         ` Tiphaine Turpin
2012-11-19 14:51           ` David House [this message]
2012-11-20  1:38           ` Francois Berenger
2012-11-20  1:57             ` Francois Berenger
2012-11-19  6:03 ` Wojciech Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK=fH+jh3zhwRZ58VVj2Bm16dEhx-fSsa1z8ifLNh_x5mDjrCw@mail.gmail.com' \
    --to=dhouse@janestreet.com \
    --cc=Tiphaine.Turpin@free.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).