import Prelude hiding(catch)
import Control.Concurrent
import Control.Exception(catch,throw,evaluate)
async :: IO a -> IO (MVar a)
async ioa = do
mVar <- newEmptyMVar
forkIO $ catch (ioa >>= putMVar mVar) (putMVar mVar . throw)
return mVar
Under 6.10. I now get a type error.
TypeError.hs:13:55:
Ambiguous type variable `e' in the constraint:
`GHC.Exception.Exception e'
arising from a use of `throw' at TypeError.hs:13:55-59
Probable fix: add a type signature that fixes these type variable(s)
Prelude> :t catch
catch :: IO a -> (IOError -> IO a) -> IO a
Prelude> :t Control.Exception.catch
Control.Exception.catch :: (GHC.Exception.Exception e) =>
IO a -> (e -> IO a) -> IO a
What changed that causes this to break between 6.8 and 6.10?
In fact, I don't even see the type error (the message is
of little help). The function throw returns an `a', so it
should unify with the required type for the handler.
I tried simplifying the problematic line to:
forkIO $ catch (ioa >>= putMVar mVar) (error "boom")
(error "boom") should also unify with anything.
Can anyone suggest other things I can try and perhaps what
is going on?
Thanks,
- Tim
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Hi Tim,
There were messages about this on the list before, I believe.
>From ghc 6.10.1 release notes, what changed is this
"Control.Exception now uses extensible exceptions. The old style of
exceptions are still available in Control.OldException, but we expect to
remove them in a future release. "
http://www.haskell.org/ghc/docs/6.10.1/html/users_guide/release-6-10-1.html
Providing a type signature for the argument of throw ought to fix it.
forkIO $ catch (ioa >>= putMVar mVar) (\e -> (putMVar mVar . throw) (e
:: IOException) )
I don't really understand what extensible exceptions are, just
that providing a type signature makes the compiler happy. This
www.haskell.org/~simonmar/papers/ext-exceptions.pdf might provide the
explanation.
Hope that helps.
Anish