caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ocaml 4.00.1 and 4.01.0 behave differently on module type constraint
@ 2014-01-28 21:19 Ashish Agarwal
  2014-01-28 21:43 ` Gabriel Scherer
  0 siblings, 1 reply; 3+ messages in thread
From: Ashish Agarwal @ 2014-01-28 21:19 UTC (permalink / raw)
  To: Caml List

[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]

Is the following an expected change from OCaml 4.00.1 to 4.01.0?

Module Foo defines a private type and this module is included in Common.
The signature within Common is defined using `module type of` with a
constraint. The different behavior shown below occurs when the private type
is a record, but not if it is a base type like string or int. In that case,
the code compiles with both 4.00.1 and 4.01.0.

$ cat a.ml
module Foo : sig
  type t = private {a:int}
end = struct
  type t = {a:int}
end

module Common : sig
  module F : module type of Foo with type t = Foo.t
end = struct
  module F = Foo
end

$ ocaml -version
The OCaml toplevel, version 4.01.0

$ ocaml a.ml
(* no errors *)

Now, change version of OCaml being used.

$ ocaml -version
The OCaml toplevel, version 4.00.1

$ ocaml a.ml
File "a.ml", line 9, characters 6-33:
Error: Signature mismatch:
       Modules do not match:
         sig module F : sig type t = Foo.t = private { a : int; } end end
       is not included in
         sig module F : sig type t = Foo.t = { a : int; } end end
       In module F:
       Modules do not match:
         sig type t = Foo.t = private { a : int; } end
       is not included in
         sig type t = Foo.t = { a : int; } end
       In module F:
       Type declarations do not match:
         type t = Foo.t = private { a : int; }
       is not included in
         type t = Foo.t = { a : int; }
       File "a.ml", line 8, characters 37-51: Expected declaration
       File "a.ml", line 2, characters 7-26: Actual declaration
       A private type would be revealed.

[-- Attachment #2: Type: text/html, Size: 2347 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] ocaml 4.00.1 and 4.01.0 behave differently on module type constraint
  2014-01-28 21:19 [Caml-list] ocaml 4.00.1 and 4.01.0 behave differently on module type constraint Ashish Agarwal
@ 2014-01-28 21:43 ` Gabriel Scherer
  2014-01-28 23:16   ` Ashish Agarwal
  0 siblings, 1 reply; 3+ messages in thread
From: Gabriel Scherer @ 2014-01-28 21:43 UTC (permalink / raw)
  To: Ashish Agarwal; +Cc: Caml List

The change of behavior was part of PR#6090:
  http://caml.inria.fr/mantis/view.php?id=6090
It was a case of the type-checker refusing more programs than necessary.

My understanding of the compatibility story of the type-system is that
future versions will not rule out semantically valid programs accepted
by previous ones (note that buggy programs previously accepted could
be ruled out), but may accept strictly more semantically valid
programs. If you need to be sure that your code compile under older
versions, you should test them explicitely.

On Tue, Jan 28, 2014 at 10:19 PM, Ashish Agarwal <agarwal1975@gmail.com> wrote:
> Is the following an expected change from OCaml 4.00.1 to 4.01.0?
>
> Module Foo defines a private type and this module is included in Common. The
> signature within Common is defined using `module type of` with a constraint.
> The different behavior shown below occurs when the private type is a record,
> but not if it is a base type like string or int. In that case, the code
> compiles with both 4.00.1 and 4.01.0.
>
> $ cat a.ml
> module Foo : sig
>   type t = private {a:int}
> end = struct
>   type t = {a:int}
> end
>
> module Common : sig
>   module F : module type of Foo with type t = Foo.t
> end = struct
>   module F = Foo
> end
>
> $ ocaml -version
> The OCaml toplevel, version 4.01.0
>
> $ ocaml a.ml
> (* no errors *)
>
> Now, change version of OCaml being used.
>
> $ ocaml -version
> The OCaml toplevel, version 4.00.1
>
> $ ocaml a.ml
> File "a.ml", line 9, characters 6-33:
> Error: Signature mismatch:
>        Modules do not match:
>          sig module F : sig type t = Foo.t = private { a : int; } end end
>        is not included in
>          sig module F : sig type t = Foo.t = { a : int; } end end
>        In module F:
>        Modules do not match:
>          sig type t = Foo.t = private { a : int; } end
>        is not included in
>          sig type t = Foo.t = { a : int; } end
>        In module F:
>        Type declarations do not match:
>          type t = Foo.t = private { a : int; }
>        is not included in
>          type t = Foo.t = { a : int; }
>        File "a.ml", line 8, characters 37-51: Expected declaration
>        File "a.ml", line 2, characters 7-26: Actual declaration
>        A private type would be revealed.
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] ocaml 4.00.1 and 4.01.0 behave differently on module type constraint
  2014-01-28 21:43 ` Gabriel Scherer
@ 2014-01-28 23:16   ` Ashish Agarwal
  0 siblings, 0 replies; 3+ messages in thread
From: Ashish Agarwal @ 2014-01-28 23:16 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: Caml List

[-- Attachment #1: Type: text/plain, Size: 2728 bytes --]

IIUC compiling this in older versions requires making the constraint `with
type t = private Foo.t`. However, garrigue says this is not semantically
correct and has deprecated this. Okay. Thanks.



On Tue, Jan 28, 2014 at 4:43 PM, Gabriel Scherer
<gabriel.scherer@gmail.com>wrote:

> The change of behavior was part of PR#6090:
>   http://caml.inria.fr/mantis/view.php?id=6090
> It was a case of the type-checker refusing more programs than necessary.
>
> My understanding of the compatibility story of the type-system is that
> future versions will not rule out semantically valid programs accepted
> by previous ones (note that buggy programs previously accepted could
> be ruled out), but may accept strictly more semantically valid
> programs. If you need to be sure that your code compile under older
> versions, you should test them explicitely.
>
> On Tue, Jan 28, 2014 at 10:19 PM, Ashish Agarwal <agarwal1975@gmail.com>
> wrote:
> > Is the following an expected change from OCaml 4.00.1 to 4.01.0?
> >
> > Module Foo defines a private type and this module is included in Common.
> The
> > signature within Common is defined using `module type of` with a
> constraint.
> > The different behavior shown below occurs when the private type is a
> record,
> > but not if it is a base type like string or int. In that case, the code
> > compiles with both 4.00.1 and 4.01.0.
> >
> > $ cat a.ml
> > module Foo : sig
> >   type t = private {a:int}
> > end = struct
> >   type t = {a:int}
> > end
> >
> > module Common : sig
> >   module F : module type of Foo with type t = Foo.t
> > end = struct
> >   module F = Foo
> > end
> >
> > $ ocaml -version
> > The OCaml toplevel, version 4.01.0
> >
> > $ ocaml a.ml
> > (* no errors *)
> >
> > Now, change version of OCaml being used.
> >
> > $ ocaml -version
> > The OCaml toplevel, version 4.00.1
> >
> > $ ocaml a.ml
> > File "a.ml", line 9, characters 6-33:
> > Error: Signature mismatch:
> >        Modules do not match:
> >          sig module F : sig type t = Foo.t = private { a : int; } end end
> >        is not included in
> >          sig module F : sig type t = Foo.t = { a : int; } end end
> >        In module F:
> >        Modules do not match:
> >          sig type t = Foo.t = private { a : int; } end
> >        is not included in
> >          sig type t = Foo.t = { a : int; } end
> >        In module F:
> >        Type declarations do not match:
> >          type t = Foo.t = private { a : int; }
> >        is not included in
> >          type t = Foo.t = { a : int; }
> >        File "a.ml", line 8, characters 37-51: Expected declaration
> >        File "a.ml", line 2, characters 7-26: Actual declaration
> >        A private type would be revealed.
> >
>

[-- Attachment #2: Type: text/html, Size: 3854 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-28 23:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-28 21:19 [Caml-list] ocaml 4.00.1 and 4.01.0 behave differently on module type constraint Ashish Agarwal
2014-01-28 21:43 ` Gabriel Scherer
2014-01-28 23:16   ` Ashish Agarwal

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).