Hi.
I have the following:
module Make_enum(X:sig type t end) = struct
open X
(* nts are even, tms are odd; we maintain a mapping *)
type t_enum = {
mutable free:int;
}
let make =
let enum = { free=0 } in
let somefun = fun (s:t) -> 3 in
fun f -> f ~somefun
end
type t' = Something
module X = struct type t = t' end
module Made = Make_enum(X)
let f = Made.make @@ fun ~somefun -> somefun
Unfortunately there is a type error in the last line (let f = …):
File "tmp.ml", line 21, characters 37-44:
Error: This expression has type t' -> int
but an expression was expected of type 'a
The type constructor t' would escape its scope
I don’t understand this because t’ is in scope.
On the other hand, the following is fine:
module Make_enum(X:sig type t end) = struct
open X
(* nts are even, tms are odd; we maintain a mapping *)
type t_enum = {
mutable free:int;
}
let make () =
let enum = { free=0 } in
let somefun = fun (s:t) -> 3 in
fun f -> f ~somefun
end
type t' = Something
module X = struct type t = t' end
module Made = Make_enum(X)
let f = Made.make () @@ fun ~somefun -> somefun
But I’m not sure why this is fine when the first example isn’t.
Thanks