[F#] How do I create and use multi-dimensional arrays in F#?

In F#, you can create and use multi-dimensional arrays using the [,] syntax. Here's how you can create and use a multi-dimensional array:

To create a multi-dimensional array, you specify the dimensions and initialize the values:

1// Create a 2-dimensional array with dimensions 3x4
2let array2D = Array2D.init 3 4 (fun i j -> i * j)

To access elements in the array, you use the indexing operator .[ , ]:

1// Access the element at row 1, column 2
2let element = array2D.[1, 2]
3printfn "%d" element

You can also assign values to elements in the array using the indexing operator:

1// Assign a new value to the element at row 0, column 1
2array2D.[0, 1] <- 42

To iterate over the elements in the array, you can use nested loops:

1// Iterate over the elements in the array
2for i = 0 to 2 do
3    for j = 0 to 3 do
4        printfn "[%d, %d] = %d" i j array2D.[i, j]

You can find more information about multi-dimensional arrays in F# in the official documentation: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/arrays