Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: Multiple value declaration in .mli file
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jérémie_Lumbroso <jeremie.lumbroso@e...>
Subject: Re: Multiple value declaration in .mli file
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