
Tom Pledger writes:
| > doquery :: (DeepSeq v) => | > Process -> String -> IO v -> IO [v] | | Can you explain what the constraint does here?
Yes. It soothes my superstitious fears about unsafeInterleaveIO.
I imagined that:
- doquery (like getContents) uses unsafeInterleaveIO to make the resulting list lazy, i.e. avoid grabbing all the rows at the outset,
Actually no. I'm not sure of the correct terminology here, but my implementation was strict wrt to reading from the database - all records are read during the IO action, and not secretly later on. Whilst I can see some benefits of reading the records lazily, wouldn't this result in problems with database connection management, locks, transactions, etc. From reading the list, it sounds like equivalent issues crop up pretty regularly with getContents. If you used the fold variant, doquery :: Process -> String -> (a -> b -> IO b) -> b -> IO b where the folding function returns an IO action, then you could process rows as you go in any case, without requiring unsafeInterleaveIO. Tim
participants (1)
-
Tim Docker