Commit eb0ff26a authored by judah's avatar judah
Browse files

Add 'catches' to MonadException. Patch from Håkan Thörngren.

parent 5b600ef9
......@@ -28,7 +28,7 @@ import Data.List
import System.IO
import System.Environment
import System.Console.Haskeline.Monads
import System.Console.Haskeline.Monads hiding (Handler)
import System.Console.Haskeline.Key
import System.Console.Haskeline.Term as Term
import System.Console.Haskeline.Prefs
......
......@@ -8,6 +8,8 @@ module System.Console.Haskeline.MonadException(
-- * Generalizations of Control.Exception
catch,
handle,
catches,
Handler(..),
finally,
throwIO,
throwTo,
......@@ -101,6 +103,18 @@ catch act handler = controlIO $ \(RunIO run) -> E.catch
handle :: (MonadException m, Exception e) => (e -> m a) -> m a -> m a
handle = flip catch
catches :: (MonadException m) => m a -> [Handler m a] -> m a
catches act handlers = controlIO $ \(RunIO run) ->
let catchesHandler handlers e = foldr tryHandler (E.throw e) handlers
where tryHandler (Handler handler) res =
case E.fromException e of
Just e' -> run $ handler e'
Nothing -> res
in E.catch (run act) (catchesHandler handlers)
data Handler m a = forall e . Exception e => Handler (e -> m a)
bracket :: MonadException m => m a -> (a -> m b) -> (a -> m c) -> m c
bracket before after thing
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment