Keith Wansbrough wrote:
> Surely it would be better to split the one stream into several infinite ones:
> 
>   splitStream :: [a] -> ([a],[a])
> 
>   splitStream xs = unzip (spl xs)
>     where spl (x:y:xs) = (x,y):(spl xs)
> 
> Then you don't have to know how many you are going to use from each stream.

If I'm not mistaken, this definition has the danger of a space leak:
Suppose you initially use a lot of elements of the first list/stream
only and then elements from the second, e.g.:

foo :: Int -> IO ()
foo n = do print . head . drop n $ xs
           print . head $ ys
   where (xs,ys) = splitStream (repeat 1)

This gives you space usage linear in n...   :-(

Cheers,
   Sven

-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.pms.informatik.uni-muenchen.de/mitarbeiter/panne


Reply via email to