OCaml 中嵌套签名的示例?
在 OCaml 中,您可以嵌套签名:
module type FOO =
sig
module type BAR
(* … *)
end
我只是想知道是否有人有任何使用中的示例,因为我想不出任何需要它的地方。我想它可能在函子的返回签名中有用,但我想不出任何具体的东西。
In OCaml, you can nest signatures:
module type FOO =
sig
module type BAR
(* … *)
end
I was just wondering if anyone had any examples of this in use, since I can’t think of any places where it would be needed. I imagine it’s probably useful in the return signatures of functors, but I can’t think of any specific things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我记得看到过一些模块(可能是电池),其中包含一个 Infix 模块,可以单独打开,并且只有在真正需要时才可以打开。例如,
通过这种方式,如果您要打开
Rational.Infix
模块,您就不会取消范围(?) 任何与Rational
中同名的函数>。我正在开发一个项目,我们使用模块来划分类型。让模块仅定义一种类型并操作该类型有助于组织;特别是当模块很小并且拥有单独的文件并不有利,并且变体类型没有意义时。
我们还使用它们,尽管它们是单独的文件(与 -mlpack 结合),用于我们生物数据所需的所有解析器——Nexus、Fasta、Phylip 等。
最后,通常在对新算法进行原型设计时,我们会先用 ocaml 编写它,然后再开发 C 版本。我们通常将 ocaml 版本保留在具有相同函数名称的内部模块中。
I recall seeing a few modules (maybe in batteries), that included an
Infix
module inside that could be opened separately and only when truly wanted. For example,In this way if you were to open the
Rational.Infix
module, you wouldn't de-scope(?) any functions with the same names as anything inRational
.I am working on a project where we use modules to demarcate
types
. Having a module define only one type and manipulate that type helps in organization; especially when the modules are small and having a separate file wouldn't be advantageous, and variant types don't make sense.We also use them, although as separate files (combined with -mlpack), for all the parsers we need for biological data --Nexus, Fasta, Phylip, et cetera.
Lastly, often when prototying a new algorithm we will write it in ocaml first, then work on a C version. We usually keep the ocaml version in a inner module with the same function names.
我想到的第一个例子: http://caml.inria .fr/pub/docs/manual-ocaml/libref/type_Map.html
(这确实是一个函子签名)
First example which came to my mind : http://caml.inria.fr/pub/docs/manual-ocaml/libref/type_Map.html
(it's indeed a functor signature)