catch (fail "...")
Brian Huffman
bhuffman@galois.com
Thu, 21 Mar 2002 16:21:43 -0800
Hi,
Here is a problem I came across recently, revealing a difference between ghci
and Hugs:
hugs> catch (error "not ok") (\e -> putStrLn "ok")
Program error: not ok
ghci> catch (error "not ok") (\e -> putStrLn "ok")
*** Exception: not ok
hugs> catch (ioError (userError "not ok")) (\e -> putStrLn "ok")
ok
ghci> catch (ioError (userError "not ok")) (\e -> putStrLn "ok")
ok
hugs> catch (fail "not ok") (\e -> putStrLn "ok")
Program error: not ok
ghci> catch (fail "not ok") (\e -> putStrLn "ok")
ok
As I expected, neither of them can catch "error", and both of them can catch
"ioError". But only ghci can catch the "fail". It seems to me that ghc has
made a convenient choice here, because if I need to raise an IO exception, it
is easier to type "fail s" than "ioError (userError s)".
However, the online Haskell report says that for IO, fail s = error s, which
is what Hugs does.
(http://www.haskell.org/onlinereport/standard-prelude.html#$iMonad$$IO)
Does anyone know the reasoning behind the design choice made in the report,
or why the ghc implementation is different? I am mainly concerned about
portability issues: particularly, is it a good idea to use fail for raising
IO exceptions?
Thanks
- Brian Huffman