Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "Jérémie Lumbroso" <jeremie.lumbroso@etu.upmc.fr>
To: caml-list@inria.fr
Subject: Re: Multiple value declaration in .mli file
Date: Fri, 15 Aug 2008 19:07:15 +0200	[thread overview]
Message-ID: <2b7b425b0808151007t57f89671s91727e328b888f8e@mail.gmail.com> (raw)

Hello,

> I guess you need it to mirror the value shadowing on the implementation side:
>    include Foo
>    let bar = baz
>
> This is legal if Foo already defines bar, and most of the time desired and
> useful.
> In the interface file you'll want to write :
>   include FOO (* Foo's signature *)
>   val bar : ...

Actually, this is untrue. I think that up until recently (3.09.2?), what
you describe would have caused an error (one of the many annoying things
about signatures in ML languages that prompted that clever paper by Ramsey
et al.).

In the latest version, 3.10.2, however, this does not produce an error,
but reaches a very peculiar state:

  <toplevel>
  # module type FOO =
    sig
      val foo : int
    end;;
  module type FOO = sig val foo : int end

  # module type BAR =
    sig
      include FOO
      val foo : string
    end;;
  module type BAR = sig val foo : int val foo : string end

  # module Bar : BAR = struct let foo = 1 end;;
  Signature mismatch:
  Modules do not match: sig val foo : int end is not included in BAR
  Values do not match: val foo : int is not included in val foo : string

  # module Bar : BAR = struct let foo = "1" end;;
  Signature mismatch:
  Modules do not match: sig val foo : string end is not included in BAR
  Values do not match: val foo : string is not included in val foo : int

  # module Bar : BAR = struct let foo = Obj.magic 1 end;;
  module Bar : BAR

  # Bar.foo;;
  Erreur de segmentation (core dumped)
  </toplevel>

Indeed, since foo is simultaneously an int and a string, the only way to
create a module conforming to the BAR signature, is to make foo an 'a. I
think this is what the original poster was referring to, and it is indeed
a bug. Noteworthy:

  <toplevel>
  # module Bar : BAR = struct let foo = Obj.magic "1" end;;
  module Bar : BAR

  # Bar.foo;;
  - : string = "1"
  </toplevel>

I am (blind) guessing that at some point, someone decided to make
redefining symbols in signatures legal, but overlooked a quirk in the way
OCaml stores signatures.

Regards,

Jérémie


             reply	other threads:[~2008-08-15 17:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-15 17:07 Jérémie Lumbroso [this message]
2008-08-15 17:36 ` Jérémie Lumbroso
  -- strict thread matches above, loose matches on Subject: below --
2008-08-14 16:25 mohamed iguernelala

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=2b7b425b0808151007t57f89671s91727e328b888f8e@mail.gmail.com \
    --to=jeremie.lumbroso@etu.upmc.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