[Haskell-cafe] Newbie Question about Error Handling
gerd_m1977 at hotmail.com
Mon Jul 25 03:50:19 EDT 2005
>We're being clever and returning from IO not a Char, but a MyMonad Char
>(mimp). Then, we run that, which either produces the answer we wanted,
>or throws an error in MyMonad.
Thanks. That did the trick! :-)
>However, it's still rather cumbersome, so here's a function similar to
>liftError that works for your monad.
> -- I'll assume you have such a function
> fromIOError :: IOError -> MyErrorType
> -- The name is intended to convey that IO errors are caught and
> -- reintroduced into MyMonad. Better suggestions welcome.
> liftIOTrap :: IO a -> MyMonad a
> liftIOTrap io = do mx <- liftIO (do x <- io
> return (return x)
> (\e -> return (throwError
> (fromIOError e))))
> foo :: MyMonad a
> foo = do
> inp <- liftIOTrap (getChar
> (\e -> if isEOFError e then return
> else throwError
Express yourself instantly with MSN Messenger! Download today it's FREE!
More information about the Haskell-Cafe