这可能是给定列表的长度已知且不需要再次计算的情况。因此,它可能被视为一种优化。
此外,一般来说,结果列表不需要与原始列表具有相同的大小。因此,这个参数可以用来设置这个长度。
这对于 Oleg 的最初想法是正确的(来源 - http://okmij.org/ftp/Haskell/perfect-shuffle.txt):
-- examples
t1 = shuffle1 ['a','b','c','d','e'] [0,0,0,0]
-- "abcde"
-- Note, that rseq of all zeros leaves the sequence unperturbed.
t2 = shuffle1 ['a','b','c','d','e'] [4,3,2,1]
-- "edcba"
-- The rseq of (n-i | i<-[1..n-1]) reverses the original sequence of elements
但是,'random-shuffle' 包的实现并不相同:
> shuffle [0..10] [0,0,0,0]
[0,1,2,3random-shuffle.hs: [shuffle] called with lists of different lengths
我认为值得跟进包维护者以了解此功能的合同。