
On 30 September 2010 15:23, C K Kashyap
Hi, I was going over the Error Handling chapter in RWH and tried out this sample -
Prelude> :m Control.Exception Prelude Control.Exception> let x=5 `div` 0 Prelude Control.Exception> let y=5 `div` 1 Prelude Control.Exception> handle (\_ -> putStrLn "Text") (print x)
<interactive>:1:0: Ambiguous type variable `e' in the constraint: `Exception e' arising from a use of `handle' at <interactive>:1:0-39 Probable fix: add a type signature that fixes these type variable(s) Prelude Control.Exception>
Could someone please tell me what the problem is and how to resolve it?
RWH was written before GHC 6.10 came out, and thus is using old-style exceptions. As of GHC 6.10.1 with base-4, the old-style exceptions were replaced with extensible exceptions. As such, you have two options: * Keep using old-style exceptions. With GHC 6.10 and 6.12, import Control.OldException instead of Control.Exception * Manually migrate the RWH code to new-style exceptions; there are two ways of doing this: - For production code, you should add explicit type signatures, etc. for your exception-handling functions passed to handle, etc. - For just playing around, use SomeException: e.g.: handle (\ SomeException{} -> putStrLn "Text") (print x) -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com