[Haskell-cafe] Shouldn't this be lazy???
David Roundy
droundy at darcs.net
Fri Jun 22 12:27:09 EDT 2007
On Fri, Jun 22, 2007 at 04:53:42PM +0100, Malcolm Wallace wrote:
> "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)
Or make this lazy with:
> main = do ...
> origLinks <- mapM (unsafeInterleaveIO . getLinksAfterImgByAttr ...) picLinks
--
David Roundy
Department of Physics
Oregon State University
More information about the Haskell-Cafe
mailing list