Here is a simple exchange in place.
module Array2D =
let swap (x1, y1) (x2, y2) (array: _[,]) =
let temp = array.[x1, y1]
array.[x1, y1] <- array.[x2, y2]
array.[x2, y2] <- temp
array
If you want a copy, just insert the call Array2D.copy:
array2D [|[|1; 2; 3|];[|4; 5; 6|]|]
|> Array2D.copy
|> Array2D.swap (0,0) (1,1)
|> printfn "%A"
source
share