ref: 2b6dae8450473faa2c60734ba213f7440d82e5cc
parent: 502e890c38881df55399dc009bc2b50c3531e967
author: Lennart Augustsson <lennart@augustsson.net>
date: Sat Apr 6 17:03:17 EDT 2024
Fix evaluate and throwIO
--- a/lib/Control/Exception.hs
+++ b/lib/Control/Exception.hs
@@ -77,17 +77,17 @@
unsafePerformIO (catch (evaluate v)
(\x -> throwIO (f x)))
--- XXX This isn't right. It should return an IO action.
+-- Evaluate a when executed, not when evaluated
evaluate :: a -> IO a
-evaluate a = seq a (return a)
+evaluate a = seq a (return ()) >> return a
-
try :: forall a e . Exception e => IO a -> IO (Either e a)
try ioa = catch (fmap Right ioa) (return . Left)
--- XXX This isn't right. It should return an IO action.
+-- Throw an exception when executed, not when evaluated
throwIO :: forall a e . Exception e => e -> IO a
-throwIO e = throw e
+throwIO e = bad >> bad -- we never reacj the second 'bad'
+ where bad = throw e
onException :: IO a -> IO b -> IO a
onException io what =
--
⑨