                         then concatPrimes ps ns
                         else concatPrimes (ps ++ [n]) ns

nPrimesImpl :: [Integer] -> Int -> Integer -> Integer -> [Integer]
nPrimesImpl ps n x blockSize
  | length ps >= n = ps
  | otherwise      = nPrimesImpl ps' n (x + blockSize + 1) blockSize
                     where ps' = (concatPrimes ps [x..x+blockSize]) 

nPrimes :: Int -> [Integer]
nPrimes n = take n $ nPrimesImpl [2, 3] n 4 100000
