OCaml 中的 a.{X} 是什么意思?
我目前正在尝试将一些 OCaml 移植到 F#。我对 OCaml 处于“深渊”,我的 F# 有点生疏了。
无论如何,OCaml 代码在 OCaml 编译器中构建得很好,但(毫不奇怪)即使打开了 ML 兼容性,F# 编译器中也会出现大量错误。有些错误看起来是保留字,但大部分错误都抱怨行中的 .{
,例如:
m.(a).(b) <- w.{a + b * c};
a、b、c 是整数。
我在 OCaml 网站、Stackoverflow、法语 O'Reilly 书的英文翻译等上进行了大量搜索,但找不到这样的东西。当然,大多数搜索工具都存在标点符号问题,这也无济于事!是的,我发现对 .
的引用用于引用记录成员,而 { }
用于定义记录,但是两者一起使用吗?从用法来看,我假设它是某种关联数组或稀疏数组?
这个语法是什么意思?最接近的 F# 等效项是什么?
I'm currently trying to port some OCaml to F#. I'm "in at the deep end" with OCaml and my F# is a bit rusty.
Anyway, the OCaml code builds fine in the OCaml compiler, but (not surprisingly) gives a load of errors in the F# compiler even with ML compatibility switched on. Some of the errors look to be reserved words, but the bulk of the errors are complaining about the .{
in lines such as:
m.(a).(b) <- w.{a + b * c};
a,b,c are integers.
I've done a lot of searching through OCaml websites, Stackoverflow, the English translation of the French O'Reilly book, etc. and cannot find anything like this. Of course it doesn't help that most search facilities have problems with punctuation characters! Yes I've found references to .
being used to refer to record members, and { }
being used to define records, but both together? From the usage, I assume it is some kind of associative or sparse array?
What does this syntax mean? What is the closest F# equivalent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有 oCaml 文档/手册的 pdf 版本:
http: //caml.inria.fr/distrib/ocaml-3.12/ocaml-3.12-refman.pdf
第 496 页(靠近底部)页),它谈到了通用数组及其 get 方法:
此外,它还指出(特别是关于一维数组):
在 F# 中,您还可以使用 Array.get 方法访问数组元素。但是,更接近的语法是
w.[a + b * c]
。简而言之,在 F# 中,使用[]
而不是{}
。There is a pdf of the oCaml documentation/manual available here:
http://caml.inria.fr/distrib/ocaml-3.12/ocaml-3.12-refman.pdf
On page 496 (toward the bottom of the page), it says of generic arrays and their get method:
Further, it says (specifically about one dimensional arrays):
In F#, you can access array elements using the
Array.get
method as well. But, a closer syntax would bew.[a + b * c]
. In short, in F#, use[]
instead of{}
.