arrays - What does a.{X} mean in OCaml? -


i'm trying port ocaml f#. i'm "in @ deep end" ocaml , f# bit rusty.

anyway, ocaml code builds fine in ocaml compiler, (not surprisingly) gives load of errors in f# compiler ml compatibility switched on. of errors reserved words, bulk of errors complaining .{ in lines such as:

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

a,b,c integers.

i've done lot of searching through ocaml websites, stackoverflow, english translation of french o'reilly book, etc. , cannot find this. of course doesn't search facilities have problems punctuation characters! yes i've found references . being used refer record members, , { } being used define records, both together? usage, assume kind of associative or sparse array?

what syntax mean? closest f# equivalent?

there pdf of ocaml documentation/manual available here:

http://caml.inria.fr/distrib/ocaml-3.12/ocaml-3.12-refman.pdf

on page 496 (toward bottom of page), says of generic arrays , method:

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

read element of generic big array. genarray.get [|i1; ...; in|] returns element of coordinates i1 in first dimension, i2 in second dimension, . . ., in in n-th dimension.

if has c layout, coordinates must greater or equal 0 , strictly less corresponding dimensions of a. if has fortran layout, coordinates must greater or equal 1 , less or equal corresponding dimensions of a. raise invalid_argument if array not have n dimensions, or if coordinates outside array bounds.

if n > 3, alternate syntax provided: can write a.{i1, i2, ..., in} instead of genarray.get [|i1; ...; in|]. (the syntax a.{...} one, 2 or 3 coordinates reserved accessing one-, two- , three-dimensional arrays described below.)

further, says (specifically 1 dimensional arrays):

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

array1.get x, or alternatively a.{x}, returns element of @ index x. x must greater or equal 0 , strictly less array1.dim if has c layout. if has fortran layout, x must greater or equal 1 , less or equal array1.dim a. otherwise, invalid_argument raised.

in f#, can access array elements using array.get method well. but, closer syntax w.[a + b * c]. in short, in f#, use [] instead of {}.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -