[Haskell-cafe] Shouldn't this be lazy???

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Fri Jun 22 11:53:42 EDT 2007


"Olivier Boudry" <olivier.boudry at gmail.com> wrote:

> I did this replacing:
>    (putStrLn . unlines . concat) origLinks
> with
>    (putStrLn . unlines . take 10 . concat) origLinks

Unfortunately, 'origLinks' has already been computed in full, before the
'take 10' applies to it.  Why?  Because 'origLinks' is the result of an
I/O action, which forces it:

> main = do ...
>           origLinks <- mapM (getLinksAfterImgByAttr ...) picLinks

What you really want to do is to trim the picLinks before you download
them. e.g.

> main = do ...
>           origLinks <- mapM (getLinksAfterImgByAttr ...) (take 10 picLinks)

Regards,
    Malcolm


More information about the Haskell-Cafe mailing list