F#按索引数组切片数组
如何重载。[]使F#array基于任意索引数组对数组进行切片 例如:F#按索引数组切片数组,f#,F#,如何重载。[]使F#array基于任意索引数组对数组进行切片 例如: let x = [|1..10|]; let indx = [|4;1|]; 虽然 [| for i in indx ->x.[i]|] 如果可以的话,最好能直接使用x.[indx]。您可以编写一个F#extension方法来接近语法 let a = [| 1..10 |] let idx = [|4;1|] type 'T ``[]`` with //' member this.Slice(ind
let x = [|1..10|];
let indx = [|4;1|];
虽然
[| for i in indx ->x.[i]|]
如果可以的话,最好能直接使用x.[indx]
。您可以编写一个F#extension方法来接近语法
let a = [| 1..10 |]
let idx = [|4;1|]
type 'T ``[]`` with //'
member this.Slice(indices:int array) =
[| for i in indices -> this.[i] |]
printfn "%A" (a.Slice idx)
但是,由于数组已经有索引器,因此似乎没有办法重载/更改它。您的示例不执行切片-它只检索数组的不同元素。切片可能是f.ex。be
x[2..6]