Real World Haskell Chapter 19 and GHC 6.10

The examples in the "error handling" chapter (19) of RWH don't run under GHC 6.10. For instance, an example might be main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0) Trying to load this results in "amigous type variable 'e' in the constraint: 'Exception e' arising from a use of 'handle' etc etc. I was able to fix this via the ludicrously complex: main2 = (handle :: (SomeException -> IO ()) -> IO () -> IO ()) (\_ -> putStrLn "Error calculating result") (print $ 5 `div` 0) Is there a more concise way to use "handle", or can someone point me to a tutorial that might explain the changes in 6.10 and in a general way how to get the RWH examples to run? Thanks, Mike

On Wed, Oct 21, 2009 at 3:29 AM, Michael Mossey
The examples in the "error handling" chapter (19) of RWH don't run under GHC 6.10.
For instance, an example might be
main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0)
Trying to load this results in "amigous type variable 'e' in the constraint: 'Exception e' arising from a use of 'handle' etc etc.
I was able to fix this via the ludicrously complex:
main2 = (handle :: (SomeException -> IO ()) -> IO () -> IO ()) (\_ -> putStrLn "Error calculating result") (print $ 5 `div` 0)
Is there a more concise way to use "handle", or can someone point me to a tutorial that might explain the changes in 6.10 and in a general way how to get the RWH examples to run?
How about: anyHandler :: IO () -> SomeException -> IO () anyHandler = const main = handle (anyHandler (putStrLn "Error calculating result")) (print $ 5 `div` 0) Luke

Michael Mossey
The examples in the "error handling" chapter (19) of RWH don't run under GHC 6.10.
For instance, an example might be
main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0)
I usually use:
main = handle (\(_ :: SomeException) -> putStrLn "error") (print $ 5 `div` 0)
...but you need the "ScopedTypeVariables" language extension.
G
--
Gregory Collins

To deal with "amigous type variable 'e'", I often write the codes like:
handle (\e@SomeException{} -> print e) (5 `div` 0)
and IIRC, the base-4.0 initially released with GHC 6.10.1, introduced
this exceptions. It enables us to specify which exception should be
caught and define types of exceptions what you want. And I hear this
is based on the paper
http://www.haskell.org/~simonmar/papers/ext-exceptions.pdf
On Wed, Oct 21, 2009 at 6:29 PM, Michael Mossey
The examples in the "error handling" chapter (19) of RWH don't run under GHC 6.10.
For instance, an example might be
main = handle (\_ -> putStrLn "error") (print $ 5 `div` 0)
Trying to load this results in "amigous type variable 'e' in the constraint: 'Exception e' arising from a use of 'handle' etc etc.
I was able to fix this via the ludicrously complex:
main2 = (handle :: (SomeException -> IO ()) -> IO () -> IO ()) (\_ -> putStrLn "Error calculating result") (print $ 5 `div` 0)
Is there a more concise way to use "handle", or can someone point me to a tutorial that might explain the changes in 6.10 and in a general way how to get the RWH examples to run?
Thanks, Mike _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi, Excerpts from Michael Mossey's message of Mi Okt 21 11:29:53 +0200 2009:
how to get the RWH examples to run?
Changing the imports from Control.Exception to Control.OldException did it for me. I am not sure whether this is what you were looking for, but it should at least allow you to follow the RWH examples, if you want to, before diving into the new Control.Exception. -ben

It's educational to port the examples yourself.
Dave
On Wed, Oct 21, 2009 at 8:56 AM, Benjamin Herr
Hi,
Excerpts from Michael Mossey's message of Mi Okt 21 11:29:53 +0200 2009:
how to get the RWH examples to run?
Changing the imports from Control.Exception to Control.OldException did it for me. I am not sure whether this is what you were looking for, but it should at least allow you to follow the RWH examples, if you want to, before diving into the new Control.Exception.
-ben _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Apparently the old exception library had convenience functions like 'arithExceptions' that could be used with 'handleJust'. handleJust arithExceptions handler thing With the new module you can write something like this (I determined this from experimentation): arithExceptionTester :: ArithException -> IO () arithExceptionTester = Just () handleJust arithExceptionTester handler thing Two questions: (1) Is there a better way to do things? (2) I don't understand quite how the type system works. Somehow, on exceptions that aren't arithmetic, arithExceptionTester returns Nothing or at least behaves that way. Yet I didn't write any code to do that. Can someone explain this? Thanks, Mike
participants (6)
-
Benjamin Herr
-
David Leimbach
-
Gregory Collins
-
Luke Palmer
-
Michael Mossey
-
Yusaku Hashimoto