[Haskell-cafe] Newbie vs. laziness
Jeff Polakow
jeff.polakow at db.com
Tue Mar 20 10:14:42 EDT 2007
Hello,
> dbCreateIndices con dtn dof = do
> let dummy = newDbItem
> let query = "SELECT id FROM " ++ (dtn dummy) ++ " ORDER BY " ++ (dof
dummy)
> ids <- liftM (map fromSql . concat ) $! quickQuery con query []
> return $ IntMap.fromList $ zip ids [0..]
>
> quickQuery returns a lazy list of results, and I expected ($!) to make
> it strict. But my program crashes if I use it this way. But, if I add
> a print to the function:
>
When using lazy DB connections in HDBC (I'm assuming you're using HDBC
since quickQuery is the pre-packaged lazy query call in HDBC), you have to
be careful about forcing all the data your'e expecting from a query on a
connection before using the same connection for something else. As the
previous poster mentioned, $! will only evaluate the list to weak head
normal form. Printing out the list will indeed force everything in the
list to be evaluated.
There is an extended discussion of this same issue (in the context of lazy
file io) in this thread from haskell-cafe:
http://www.haskell.org/pipermail/haskell-cafe/2007-March/023498.html
-Jeff
---
This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070320/290b34ee/attachment.htm
More information about the Haskell-Cafe
mailing list