Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 阵列切片的奇怪行为_Arrays_F#_Slice - Fatal编程技术网

Arrays 阵列切片的奇怪行为

Arrays 阵列切片的奇怪行为,arrays,f#,slice,Arrays,F#,Slice,执行简单的切片: > let a = [| 'a'..'d' |];; val a : char [] = [|'a'; 'b'; 'c'; 'd'|] 现在使用空区域进行尝试: > a.[1..2], [1..2];; val it : char [] * int list = ([|'b'; 'c'|], [1; 2]) 似乎有效且合理-我们得到了两个空序列 但它在这里失败了: > a.[1..0], [1..0];; val it : char [] * int li

执行简单的切片:

> let a = [| 'a'..'d' |];;
val a : char [] = [|'a'; 'b'; 'c'; 'd'|]
现在使用空区域进行尝试:

> a.[1..2], [1..2];;
val it : char [] * int list = ([|'b'; 'c'|], [1; 2])
似乎有效且合理-我们得到了两个空序列

但它在这里失败了:

> a.[1..0], [1..0];;
val it : char [] * int list = ([||], [])
>a[5..0];;
System.OverflowException:算术运算导致溢出。
地址:$FSI_0018.main@()
由于错误而停止
当然,对于[5..0]>a.[i].[code>中的i,有一个变通方法。但是我没有理解为什么
a[5..0]
失败?为什么不直接返回空数组呢?这种行为有什么原因吗?

这是一个bug

虽然数组切片和范围表达式是不同的概念(例如,不能使用
a[1..2..5]
),但它们的行为应该一致


请注意,
a.[start..finish]
finish-start时会发生异常。您知道F#的“官方”错误跟踪程序在哪里吗?您可以将错误报告发送到fsbug(位于)microsoft(dot)com。
> a.[5..0];;
System.OverflowException: Arithmetic operation resulted in an overflow.
   at <StartupCode$FSI_0018>.$FSI_0018.main@()
Stopped due to error
let inline GetArraySlice (arr: _[]) start finish = 
    let start  = (match start with None -> 0 | Some n -> n) 
    let finish = (match finish with None -> arr.Length - 1 | Some n -> n) 
    GetArraySub arr start (finish - start + 1)
let inline GetArraySub arr (start:int) (len:int) =
    let dst = zeroCreate len   
    for i = 0 to len - 1 do 
        SetArray dst i (GetArray arr (start + i))
    dst