给定一个简单的工厂:
module type Factory = sig type t val create : unit -> t end
module FactoryImpl : Factory = struct
type t = string
let create: unit -> t = fun () -> "aaa"
end
let factory: (module Factory) = (module FactoryImpl)
let f = let module F = (val factory) in F.create ()
编译器抱怨:
This has type:
F.t
But somewhere wanted:
F.t
The type constructor F.t would escape its scope
我对 OCaml 模块很陌生,不知道如何告诉编译器f
是那种类型Factory.t