有没有办法在不使用该模块中的函数的情况下打印模块类型?

Is there any way to print a module type without using a function in that module?

假设我有这样一个模块:

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 中的类型系统(就像在所有语言中一样),但一般来说,您应该像避免瘟疫一样避免它们。