我实现了这个答案的一个版本/sf/answers/694429781/(我不知道回答的人的意图是什么)
sublistofsize 0 _ = [[]]
sublistofsize _ [] = []
sublistofsize n (x : xs) = sublistsThatStartWithX ++ sublistsThatDontStartWithX
where sublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs
sublistsThatDontStartWithX = sublistofsize n xs
Run Code Online (Sandbox Code Playgroud)
我不确定的是什么 sublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs
我假设map(x :)在性能方面提出了问题,但不确定如何解决它.我做过剖析print $ length $ sublistofsize 5 $ primesToTakeFrom 50
COST CENTRE MODULE no. entries %time %alloc %time %alloc
sublistofsize Main 112 4739871 46.9 39.9 96.9 100.0
sublistofsize.sublistsThatDontStartWithX Main 124 2369935 2.2 0.0 2.2 …Run Code Online (Sandbox Code Playgroud)