[Haskell-cafe] Real World Haskell Chapter 19 and GHC 6.10

Yusaku Hashimoto nonowarn at gmail.com
Wed Oct 21 10:37:29 EDT 2009


To deal with "amigous type variable 'e'", I often write the codes like:

    handle (\e at 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 <mpm at alumni.caltech.edu> wrote:
> 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list