Least expensive way to construct cyclic list in Haskell
问题 So if I want to construct a circular list of n 0's and 1 1, which of the following ways is better/cheaper? And is there an even better/cheaper way? Taking into account that n is an Integer and may be large (though realistically its not going to exceed 2^32). aZerosAndOnes :: Integer -> [Int] aZerosAndOnes n | n >= 0 = cycle (genericReplicate n 0 ++ [1]) | otherwise = [] versus bZerosAndOnes :: Integer -> [Int] bZerosAndOnes n | n >= 0 = tail (cycle (1 : genericReplicate n 0)) | otherwise = []