Io 是否有任何方法可以在不使用模块中的函数的情况下打印模块类型?
假设我有这样一个模块:Io 是否有任何方法可以在不使用模块中的函数的情况下打印模块类型?,io,ocaml,Io,Ocaml,假设我有这样一个模块: module type MyModule = sig type t func1 : ... -> t end (* Implementation *) module SomeModule : MyModule = struct type t = int let func1 ... : t = (* do something and return type t *)
module type MyModule =
sig
type t
func1 : ... -> t
end
(* Implementation *)
module SomeModule : MyModule =
struct
type t = int
let func1 ... : t =
(* do something and return type t *)
end
现在,我在模块外的某个地方调用了func1,并获得了一个类型为MyModule.t
的值:
let x = SomeModule.func1 ... in
print_int x (* Which doesn't works *)
所以我想知道有没有办法打印x?
谢谢你的回答 简短的回答是“不”。您专门将类型t
抽象化,因此无法在SomeModule
外部使用类型t
的值
当然,在OCaml中有一些秘密的方法可以破坏类型系统(就像在每种语言中一样),但是一般来说,您应该像避免瘟疫一样避免它们