I want to sort a slice of an array, but the following code doesn't work as expected:
let arr = [|2; 8; 4; 1|]
Array.sortInPlace arr
printfn "%A" arr //1,2,4,8
let mutable arr2 = [|2; 8; 4; 1|]
Array.sortInPlace arr2.[1..]
printfn "%A" arr2.[1..] //8,4,1. Expected: 1,4,8
printfn "%A" arr2 //2,8,4,1. Expected: 2,1,4,8
The mutable keyword has no effect one way or the other.
How do I sort a continuous section of an array in-place in F#?