Reputation: 12793
I have the following code that compiles fine in OCaml 3.11:
module type T =
sig
type test
val create : int -> test (* line 44 *)
...
end
...
type test = (string, clause list) Hashtbl.t
let create = Hashtbl.create (* line 332 *)
But when I try to compile it with OCaml 4.01, it gives me the following error:
Error: Signature mismatch:
...
Values do not match:
val create : ?random:bool -> int -> ('a, 'b) Hashtbl.t
is not included in
val create : int -> theory
File "test1.ml", line 44, characters 2-28: Expected declaration
File "test1.ml", line 332, characters 6-12: Actual declaration
make[1]: *** [test1.cmo] Error 2
make: *** [byte-code] Error 2
What changed in OCaml 4 so that it now can't compile it? I am sure it has a very easy explanation but I am still learning the inner workings of OCaml types.
Upvotes: 1
Views: 72
Reputation: 47934
The type of the function has changed --of course! Since the addition is of an optional argument, it will affect anyone who is aliasing the function (which will carry over the type, inc. the optional parameter). You will have to eta-expand the arguments of the create function to fix this issue, as in...
let create i = Hashtbl.create i
In fact it should be noted that you only need to eta-expand one argument to remove the optional arguments from the inferred type signature as in...
let create ?random1 ?random2 x y z = Hashtbl.create (x+y+z);;
(* ?random1:'a -> ?random2:'b -> int -> int -> int -> ('c, 'd) Hashtbl.t *)
let create7 = create 7;;
(* create7 : int -> int -> ('_a, '_b) Hashtbl.t *)
Upvotes: 3