[Haskell-cafe] Takusen and strictness

Bayley, Alistair Alistair_Bayley at invescoperpetual.co.uk
Fri Mar 2 09:48:17 EST 2007


> From: Paul Moore [mailto:p.f.moore at gmail.com] 
> 
> > If you don't need the entire list at once, then push your processing
> > into the iteratee.
> 
> Hmm, that's what I was trying to avoid. The article I mentioned made a
> strong point that laziness allows you to factor out processing from IO
> - so you can write (for example)
> 
> main = do
>   s <- getContents
>   let r = map processIt (lines s)
>   putStr (unlines r)
> 
> and laziness means that IO is performed "on demand", so that the above
> code never has to read the whole input into memory. I was hoping to do
> something similar for database access, with runSql taking the place of
> getContents. Having to incorporate "processIt" into the database
> access code breaks this idiom.

There's a big difference between getContents and Takusen: getContents
has a non-trivial implementation (using unsafeInterleaveIO) that allows
it to return data lazily. Takusen has no such implementation. I'm not
sure if it would be possible. I don't really understand how getContents
works; is there any advice or guidelines as to how to use (or abuse)
unsafeInterleaveIO? Some googling has found:
  http://therning.org/magnus/archives/249
  http://www.haskell.org/pipermail/haskell-cafe/2007-January/021373.html
  http://www.haskell.org/pipermail/haskell-cafe/2007-January/021407.html
 
http://haskell.org/haskellwiki/IO_inside#unsafePerformIO_and_unsafeInter
leaveIO


> That's what my earlier code looked like, and I found it harder to
> understand than the getContents/process/put approach. I'm trying to
> explore ways of factoring data manipulation code out of database
> access functions, but maybe that's not the right way of doing it.

I don't think it's possible to pursue this style of programming with
Takusen. If you do, you'll have to process the entire result-set into a
data structure and then process it, which has obvious memory
implications.


Alistair
*****************************************************************
Confidentiality Note: The information contained in this message,
and any attachments, may contain confidential and/or privileged
material. It is intended solely for the person(s) or entity to
which it is addressed. Any review, retransmission, dissemination,
or taking of any action in reliance upon this information by
persons or entities other than the intended recipient(s) is
prohibited. If you received this in error, please contact the
sender and delete the material from any computer.
*****************************************************************


More information about the Haskell-Cafe mailing list