一个。{X}在OCaml中意味着什么?

时间:2021-08-13 01:13:09

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.

我正在尝试将一些OCaml移植到F#。我与OCaml“陷入了困境”,我的F#有点生疏。

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:

无论如何,OCaml代码在OCaml编译器中构建得很好,但是(毫不奇怪)即使在ML兼容性开启的情况下也会在F#编译器中产生大量错误。有些错误看起来像是保留字,但是大部分错误都是抱怨。{以下行:

 m.(a).(b) <- w.{a + b * c};

a,b,c are integers.

a,b,c是整数。

I've done a lot of searching through OCaml websites, *, 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?

我已经通过OCaml网站,*,法国O'Reilly书籍的英文翻译等进行了大量搜索,但却找不到这样的内容。当然,大多数搜索工具都有标点符号问题,这无济于事!是的我找到了参考资料。用于引用记录成员,{}用于定义记录,但两者一起?根据用法,我假设它是某种关联或稀疏数组?

What does this syntax mean? What is the closest F# equivalent?

这个语法是什么意思?什么是最接近的F#等价物?

1 个解决方案

#1


9  

There is a pdf of the oCaml documentation/manual available here:

这里有oCaml文档/手册的pdf:

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:

在页496(页面底部),它说的是通用数组及其get方法:

val get : (’a, ’b, ’c) t -> int array -> ’a

val get:('a,'b,'c)t - > int array - >'a

Read an element of a generic big array. Genarray.get a [|i1; ...; iN|] returns the element of a whose coordinates are i1 in the first dimension, i2 in the second dimension, . . ., iN in the N-th dimension.

读取通用大数组的元素。 Genarray.get a [| i1; ...; iN |]返回其坐标为第一维i1的元素,第二维i2的元素。 。 。,iN在第N维。

If a has C layout, the coordinates must be greater or equal than 0 and strictly less than the corresponding dimensions of a. If a has Fortran layout, the coordinates must be greater or equal than 1 and less or equal than the corresponding dimensions of a. Raise Invalid_argument if the array a does not have exactly N dimensions, or if the coordinates are outside the array bounds.

如果a具有C布局,则坐标必须大于或等于0并且严格小于a的相应尺寸。如果a具有Fortran布局,则坐标必须大于或等于1且小于或等于a的相应尺寸。如果数组a没有精确的N维,或者坐标位于数组边界之外,则引发Invalid_argument。

If N > 3, alternate syntax is provided: you can write a.{i1, i2, ..., iN} instead of Genarray.get a [|i1; ...; iN|]. (The syntax a.{...} with one, two or three coordinates is reserved for accessing one-, two- and three-dimensional arrays as described below.)

如果N> 3,则提供替代语法:您可以编写。{i1,i2,...,iN}而不是Genarray.get a [| i1; ...;在|]。 (具有一个,两个或三个坐标的语法a。{...}保留用于访问一维,二维和三维数组,如下所述。)

Further, it says (specifically about one dimensional arrays):

此外,它说(特别是关于一维数组):

val get : (’a, ’b, ’c) t -> int -> ’a

val get:('a,'b,'c)t - > int - >'a

Array1.get a x, or alternatively a.{x}, returns the element of a at index x. x must be greater or equal than 0 and strictly less than Array1.dim a if a has C layout. If a has Fortran layout, x must be greater or equal than 1 and less or equal than Array1.dim a. Otherwise, Invalid_argument is raised.

Array1.get a x,或者a。{x},返回at索引x的元素。 x必须大于或等于0且严格小于Array1.dim a如果a具有C布局。如果a具有Fortran布局,则x必须大于或等于1且小于或等于Array1.dim a。否则,引发Invalid_argument。

In F#, you can access array elements using the Array.get method as well. But, a closer syntax would be w.[a + b * c]. In short, in F#, use [] instead of {}.

在F#中,您也可以使用Array.get方法访问数组元素。但是,更接近的语法是w。[a + b * c]。简而言之,在F#中,使用[]而不是{}。

#1


9  

There is a pdf of the oCaml documentation/manual available here:

这里有oCaml文档/手册的pdf:

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:

在页496(页面底部),它说的是通用数组及其get方法:

val get : (’a, ’b, ’c) t -> int array -> ’a

val get:('a,'b,'c)t - > int array - >'a

Read an element of a generic big array. Genarray.get a [|i1; ...; iN|] returns the element of a whose coordinates are i1 in the first dimension, i2 in the second dimension, . . ., iN in the N-th dimension.

读取通用大数组的元素。 Genarray.get a [| i1; ...; iN |]返回其坐标为第一维i1的元素,第二维i2的元素。 。 。,iN在第N维。

If a has C layout, the coordinates must be greater or equal than 0 and strictly less than the corresponding dimensions of a. If a has Fortran layout, the coordinates must be greater or equal than 1 and less or equal than the corresponding dimensions of a. Raise Invalid_argument if the array a does not have exactly N dimensions, or if the coordinates are outside the array bounds.

如果a具有C布局,则坐标必须大于或等于0并且严格小于a的相应尺寸。如果a具有Fortran布局,则坐标必须大于或等于1且小于或等于a的相应尺寸。如果数组a没有精确的N维,或者坐标位于数组边界之外,则引发Invalid_argument。

If N > 3, alternate syntax is provided: you can write a.{i1, i2, ..., iN} instead of Genarray.get a [|i1; ...; iN|]. (The syntax a.{...} with one, two or three coordinates is reserved for accessing one-, two- and three-dimensional arrays as described below.)

如果N> 3,则提供替代语法:您可以编写。{i1,i2,...,iN}而不是Genarray.get a [| i1; ...;在|]。 (具有一个,两个或三个坐标的语法a。{...}保留用于访问一维,二维和三维数组,如下所述。)

Further, it says (specifically about one dimensional arrays):

此外,它说(特别是关于一维数组):

val get : (’a, ’b, ’c) t -> int -> ’a

val get:('a,'b,'c)t - > int - >'a

Array1.get a x, or alternatively a.{x}, returns the element of a at index x. x must be greater or equal than 0 and strictly less than Array1.dim a if a has C layout. If a has Fortran layout, x must be greater or equal than 1 and less or equal than Array1.dim a. Otherwise, Invalid_argument is raised.

Array1.get a x,或者a。{x},返回at索引x的元素。 x必须大于或等于0且严格小于Array1.dim a如果a具有C布局。如果a具有Fortran布局,则x必须大于或等于1且小于或等于Array1.dim a。否则,引发Invalid_argument。

In F#, you can access array elements using the Array.get method as well. But, a closer syntax would be w.[a + b * c]. In short, in F#, use [] instead of {}.

在F#中,您也可以使用Array.get方法访问数组元素。但是,更接近的语法是w。[a + b * c]。简而言之,在F#中,使用[]而不是{}。