Using DeepSeq for exception ordering
Albert Y. C. Lai
trebla at vex.net
Thu Nov 8 18:24:57 CET 2012
On 12-11-08 07:12 AM, Simon Hengel wrote:
> I was just going to say that I can give at least one counterexample
> where this does not hold:
>
> evaluate (('a' : undefined) `deepseq` return () :: IO ())
> throwIO exceptionB
>
> But then I realized that here exceptionA is optimized away altogether.
> For me this smells like a bug. Is this related to [1]?
>
> [1] http://hackage.haskell.org/trac/ghc/ticket/2273
Interesting. A few more tests (all GHC 7.4.2, linux, x86 32-bit, use
"ghc -O" to compile):
The following cases throw A:
import Control.DeepSeq
import Control.Exception
main = do
evaluate (('a' : error "A") `deepseq` return () :: Maybe ())
throwIO (userError "B")
main = do
evaluate (('a' : error "A") `deepseq` ())
throwIO (userError "B")
main = do
evaluate (('a' : error "A") `deepseq` True)
throwIO (userError "B")
main = do
x <- evaluate (('a' : error "A") `deepseq` putStrLn "hi")
x
throwIO (userError "B")
The following cases throw B:
main = do
evaluate (('a' : error "A") `deepseq` return () :: IO ())
throwIO (userError "B")
main = do
evaluate (('a' : error "A") `deepseq` putStrLn "hi")
throwIO (userError "B")
main = do
evaluate (('a' : error "A") `deepseq` getLine)
throwIO (userError "B")
More information about the Glasgow-haskell-users
mailing list