<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta content="text/html; charset=ISO-8859-1"
<body bgcolor="#ffffff" text="#000000">
Check out the "evaluate" function in Control.Exception.<br>
Also note that if you apply seq to an IO action, you do *not* force
the result, only the action that will eventually produce the result.<br>
On 9/15/10 2:13 AM, Jeroen van Maanen wrote:
<blockquote cite="mid:4C908E2B.firstname.lastname@example.org" type="cite">
<pre wrap="">The past year I have been working on a port of my machine learning project named LExAu from Java to Haskell. I'm still very glad I took the jump, because the complexity curve appears to be log shaped rather than exp shaped. In one year I almost got to the functionality that had taken me five years to produce in Java (of course it helped a lot that I had a working prototype this time).
There is one thing that still bothers me though: when I write seq or $! it doesn't seem to have any effect!
Currently I am trying to add some exception handling to help me debug the system, but the code that I managed to produce depends on the logging statement to produce the desired result. :-( It looks like this, and only works when I uncomment the line '-- logger "Check sum": [...]', otherwise the exception is caught by the try around the body of the thread that this code runs in:
do logger "Received update" [showString label, logs update]
do maybeUpdatedModel <- return $ f update startModel
theCheckSum <- return $ liftM checkSum maybeUpdatedModel
-- logger "Check sum" [showString label, shows theCheckSum]
return $! seq theCheckSum maybeUpdatedModel
case result of
Right theMaybeNextModel -> return theMaybeNextModel
Left exception ->
do let exc :: SomeException
exc = exception
logger "Exception" [showString label, shows exception]
logger "Maybe next model" [showString label, logs maybeNextModel]
For more context see:
<a class="moz-txt-link-freetext" href="http://lexau.svn.sourceforge.net/viewvc/lexau/branches/totem/src/LExAu/Pipeline/Concurrent.hs?revision=326&view=markup">http://lexau.svn.sourceforge.net/viewvc/lexau/branches/totem/src/LExAu/Pipeline/Concurrent.hs?revision=326&view=markup</a>
after line 241.
Can someone explain why a few showStrings a shows and a putStrLn are more effective in forcing the check sum to be computed (which necessarily evaluates the complete updated model and reveals the lurking exception) than the seq on the line just below the logging statement?
Haskell-Cafe mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a>