Alex Queiroz wrote:
> 
>     I don't quite get how ($!) works. I have this function:
> 
>   ids <- liftM (map fromSql . concat ) $! quickQuery con query []

There's a difference between an IO action and the result of said action,
and similarly there's a difference between making sure an action is
evaluated and making sure the result of executing the action is
evalulated.  You did the former.

If you really wanted to evaluate the result to WHNF (only) before
finishing dbCreateIndices, this would work:

>   ids <- liftM (map fromSql . concat ) $ quickQuery con query []
>   ids `seq` return $ IntMap.fromList $ zip ids [0..]

But you probably need to evaluate the complete list, so you need more:

>   ids <- liftM (map fromSql . concat ) $ quickQuery con query []
>   foldr seq () ids `seq` return $ IntMap.fromList $ zip ids [0..]

Of course, if you insist on using ($!), that's also possible:

>   ids <- liftM (map fromSql . concat ) $ quickQuery con query []
>   return $ IntMap.fromList $ flip zip [0..] $! foldr seq ids ids


HTH.

-Udo.

Attachment: signature.asc
Description: Digital signature

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

Reply via email to