Hi!
I'm not quite sure, whether this is a bug at all, so maybe someone can
explain this behaviour to me:
Consider the following piece of code:
\begin{code}
import Exception
foo = do
res <- tryAll (someObscureComputationThatThrowsErrors)
putStr "This is immediately printed: "
print res -- here res gets evaluated (which usually takes some time)
-- and the error occurs despite the `tryAll'
someObscureComputationThatThrowsErrors :: (Int,Int)
someObscureComputationThatThrowsErrors = runST $
-- ...
if condition
then return (1,1)
else error "BANG"
main = foo
\end{code}
The above code (i.e., the code, from where this example is derived) lets the
program die with error "BANG" (if condition is False), although there is a
`tryAll' statement, that should catch these errors!
This (mis)behaviour goes away, if I slightly modify the function, like:
\begin{code}
someObscureComputationThatThrowsErrors' :: (Int,Int)
someObscureComputationThatThrowsErrors' =
forceEval someObscureComputationThatThrowsErrors
where
forceEval x = if x == x then x else x
\end{code}
i.e., the error is caught, if I *force the evaluation* inside the `tryAll'
statement, which is what I expected tryAll to do...
BTW: in hslibs/lang/Exception.lhs, `tryAll' is defined with
"tryAll a = ... (a `seq` return (Right a)) ..."
^^^
How is the possible, that the error emerges from the `tryAll' statement?
Is there another possible reason for this behaviour?
(ghc-4.07, CVS version 2000/05/04)
[Sorry, but I was unable to find a small example, that triggers this "bug".
Things like (tryAll (runST (return (error "BANG")))) work as expected]
Cheers,
Michael
--
Lehrstuhl-Kinderkrippe Michael Weber <[EMAIL PROTECTED]>
Lehrstuhl für Informatik II
RWTH Aachen
WWW: http://www-i2.informatik.rwth-aachen.de/Software/Haskell/