caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Milan Stanojević" <milanst@gmail.com>
Cc: Markus Mottl <markus.mottl@gmail.com>, Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] strange error with packed modules and module type of
Date: Fri, 8 Jun 2012 08:37:18 +0900	[thread overview]
Message-ID: <5ECBEDB2-9C7C-45B7-98F7-36E10B2BB07D@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAKR7PS-b2tidq=Ho7BzXukVr7KO4J_x9T3Fx5VMV5WEmouT=Bw@mail.gmail.com>

On 2012/06/08, at 4:53, Milan Stanojević wrote:

> If I just do
> ocamlopt.opt -for-pack G -c foo.mli foo.ml
> ocamlopt.opt -pack -o g.cmx foo.cmx
> 
> that is, forget all the fancyness with std and specifying interface
> for G, the resulting G module has the type
> sig module Foo : sig type t = G.Foo.t val x : t end end
> 
> So somehow the resulting interface of G is defined in terms of itself?!
> 
> Should I just file this problem on ocaml mantis?

This is the right behavior.
To understand it, you should distinguish between the interface (or abstract signature)
and the concrete type of a module (its strengthened signature).
The above type is not the interface of G (which of course should not refer to
itself by name) but its strengthened signature (its exact type).
Since an abstract signature has a meaning independently of the module you use it
for, it is strengthened so that the abstract components of the interface
refer explicitly to the module.

See this dialogue:

# module M : sig type t val x : int end = struct type t = int let x = 1 end;;
module M : sig type t val x : int end
# module N = M;;
module N : sig type t = M.t val x : int end

> p.s the only way I was able to get interface for G is to make a helper
> program that uses G with a wrong signature and get the compiler to
> give me the type in the error message. Is there a better way?

As shown above, you can define another module as an alias.
It will give you the strengthened signature for your original module.

You can also see its abstract signature, using "module type of".

# module type S = module type of M;;
module type S = sig type t val x : int end

Jacques Garrigue

  reply	other threads:[~2012-06-07 23:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30  0:25 Milan Stanojević
2012-05-30  2:30 ` Markus Mottl
2012-06-07 19:53   ` Milan Stanojević
2012-06-07 23:37     ` Jacques Garrigue [this message]
2012-06-08 20:36       ` Milan Stanojević

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=5ECBEDB2-9C7C-45B7-98F7-36E10B2BB07D@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=markus.mottl@gmail.com \
    --cc=milanst@gmail.com \
    /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).