> 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]
失败?为什么不只返回空数组?这种行为有什么原因吗?