OCaml:全局模块绑定

时间:2016-09-11 19:29:54

标签: ocaml

我正在研究OCaml项目,我想为外部模块声明一些全局绑定。例如:

module Test = struct

  open Another_module

  let module AM = Another_module 


  let func1 a =
     AM.process a

  let func2 a =
     AM.process a

end

但是,当我编译一些如上组织的代码时,我总是得到一个全局模块绑定句子的编译错误。

Parse error: "in" expected after [module_binding0] (in [str_item])

我在这里做错了吗?谁能给我一些帮助?谢谢!

1 个答案:

答案 0 :(得分:2)

结构内部模块定义的语法是

module Name = module-expression 

关键字序列let module仅用于模块的本地绑定:

let module Name = module-expression in Name.x + Name.y

所以你需要写

module Test = struct
  module AM = Another_module 
  let func1 a =
     AM.process a
end

请注意,module AM = Another_module不会使模块名称AMAnother_module完全互换:由于方式的原因,它们在仿函数的参数中使用时不等效。< / p>