Prelude.catch vs. Exception.catch
Ashley Yakeley
ashley@semantic.org
Sun, 12 May 2002 18:34:30 -0700
I notice that Prelude.catch and Exception.catch behave differently, even
though they both have the same type signature (and name). Exception.catch
catches exceptions that Prelude.catch does not.
For instance, it is possible to bind pure functional exceptions into the
IO monad using Exception.evaluate:
peUndef :: String;
peUndef = undefined;
ioUndef :: IO String;
ioUndef = Exception.evaluate peUndef;
These can be caught with Exception.catch:
main :: IO ();
main = do
{
result <- Exception.catch (ioUndef)
(\e -> return ("got exception: " ++ (show e)));
hPutStr stderr (result ++ "\n");
};
got exception: Prelude.undefined
...but not with Prelude.catch:
main :: IO ();
main = do
{
result <- Prelude.catch (ioUndef)
(\e -> return ("got exception: " ++ (show e)));
hPutStr stderr (result ++ "\n");
};
Fail: Prelude.undefined
What's up with that?
--
Ashley Yakeley, Seattle WA