Hallo list,

    I don't quite get how ($!) works. I have this function:

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:

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 []
  print ids
  return $ IntMap.fromList $ zip ids [0..]

print makes the ids list strict and all is well. How is the correct
way to use ($!) ?

Cheers,
--
-alex
http://www.ventonegro.org/
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to