let rec take n s = if n <= 0 then [] else let hd, tl = s () in hd :: (take (n-1) tl)