Prelude.catch vs. Exception.catch

Ashley Yakeley
Mon, 13 May 2002 22:07:11 -0700

At 2002-05-13 08:44, Simon Marlow wrote:

>Prelude.catch catches IO exceptions only, because this is what the
>Haskell report specifies.


>The idea is
>that if you want to use Exceptions in their full glory, you:
>	import qualified Exception

I've noticed something a bit unusual about Exception.catch. It seems it 
can't catch "return undefined" by itself. Consider these values of type 
"IO String":

     iouPure :: IO String;
     iouPure = undefined;

     iouError :: IO String;
     iouError = error "error";

These aren't even an IO actions, they're simply bottom. Straightforward 
enough. But they _will_ be caught by Exception.catch.

     iouFail :: IO String;
     iouFail = fail "failure";

     iouEvaluate :: IOString;
     iouEvaluate = Exception.evaluate undefined;

These two are IO actions that "fail" when executed. They will also be 
caught by Exception.catch.

     iouReturn :: IO String;
     iouReturn = return undefined;

This one is an IO action that "succeeds" when executing. It _won't_ be 
caught by Exception.catch, which will instead simply return the undefined 

I'm not sure what to make of this...

Ashley Yakeley, Seattle WA