title: subsequences of length n from list performance
body: <p>I implemented a version of this answer <a href="https://stackoverflow.com/a/9920425/1261166">https://stackoverflow.com/a/9920425/1261166</a> (I don't know what was intended by the person answering)</p>
  
  <pre><code>sublistofsize 0 _        = [[]]
  sublistofsize _ []       = []
  sublistofsize n (x : xs) = sublistsThatStartWithX ++ sublistsThatDontStartWithX
    where sublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs
          sublistsThatDontStartWithX = sublistofsize n xs
  </code></pre>
  
  <p>what I'm unsure of is <code>sublistsThatStartWithX = map (x:) $ sublistofsize (n-1) xs</code></p>
  
  <p>I assume that map (x:) gives a problem performance wise, but not sure of how to solve it. I've done profiling on <code>print $ length $ sublistofsize 5 $ primesToTakeFrom 50</code></p>
  
  <pre><code>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    0.0
   sublistofsize.sublistsThatStartWithX     Main                                          116     2369935   47.8   60.1    47.8   60.1
  </code></pre>
  
  <p>Did I implement it in a good way?
  Are there any faster ways of doing it?</p>