我有两个函数(count和listOfNths),它们都接受参数并生成一个列表。我想压缩这两个函数生成的列表。我该怎么做呢?
我尝试写zip listOfNths count
,但那不起作用。
count n = [ x | x <- [0..n-1]]
everyf n [] = []
everyf n as = head as : everyf n (drop n as)
listOfNths :: Int -> [a] -> [[a]]
listOfNths n xs = map (\x -> everyf n (drop x xs)) [0..n-1]
只是旁注:函数listOfNths使用了另一个函数(everyf),但这并不重要。
答案 0 :(得分:3)
如果我理解正确,您可以使用简单的map
:
fn n xs = map (\x -> (everyf n $ drop x xs, x)) [0..n-1]
如果你坚持使用zip,那么你必须在压缩前评估这些功能:
fn n xs = zip (listOfNths n xs) (count n)