public
Created

Removing parts of an infinite list

  • Download Gist
Foo.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12
-- http://stackoverflow.com/questions/13026095/lack-of-understanding-infinite-lists-and-seq-operator
module Main
where
 
main :: IO ()
main = print (take 100 (foo 2 [1..]))
 
foo :: Int -> [a] -> [a]
foo n l = go l
where
go xs = let (toKeep, rest) = splitAt n xs
in toKeep ++ go (drop n rest)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.