> 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: Arithmetic operation resulted in an overflow.
at <StartupCode$FSI_0018>.$FSI_0018.main@()
Stopped due to error
当然,有一种解决方法是使用
[| for i in [5..0] -> a.[i] |]
。但是,我不明白为什么 a.[5..0]
会失败?为什么不能返回一个空数组呢?这种行为有任何原因吗?