haskeline-0.7.0.3: A command-line interface for user input, written in Haskell.

Safe HaskellNone

System.Console.Haskeline.MonadException

Contents

Description

This module redefines some of the functions in Control.Exception to work for more general monads built on top of IO.

Synopsis

The MonadException class

class MonadIO m => MonadException m where

An instance of MonadException is generally made up of monad transformers layered on top of the IO monad.

The controlIO method enables us to "lift" a function that manages IO actions (such as bracket or catch) into a function that wraps arbitrary monadic actions.

Methods

controlIO :: (RunIO m -> IO (m a)) -> m a

Generalizations of Control.Exception

catch :: (MonadException m, Exception e) => m a -> (e -> m a) -> m a

handle :: (MonadException m, Exception e) => (e -> m a) -> m a -> m a

finally :: MonadException m => m a -> m b -> m a

throwIO :: (MonadIO m, Exception e) => e -> m a

throwTo :: (MonadIO m, Exception e) => ThreadId -> e -> m ()

bracket :: MonadException m => m a -> (a -> m b) -> (a -> m c) -> m c

Helpers for defining "wrapper" functions

liftIOOp :: MonadException m => ((a -> IO (m b)) -> IO (m c)) -> (a -> m b) -> m c

Lift a IO operation

 wrap :: (a -> IO b) -> IO b

to a more general monadic operation

 liftIOOp wrap :: MonadException m => (a -> m b) -> m b

For example:

  liftIOOp (withFile f m) :: MonadException m => (Handle -> m r) -> m r
  liftIOOp alloca :: (MonadException m, Storable a) => (Ptr a -> m b) -> m b
  liftIOOp (withForeignPtr fp) :: MonadException m => (Ptr a -> m b) -> m b

liftIOOp_ :: MonadException m => (IO (m a) -> IO (m a)) -> m a -> m a

Lift an IO operation

 wrap :: IO a -> IO a

to a more general monadic operation

 liftIOOp_ wrap :: MonadException m => m a -> m a

Internal implementation

newtype RunIO m

A RunIO function takes a monadic action m as input, and outputs an IO action which performs the underlying impure part of m and returns the ''pure'' part of m.

Note that (RunIO return) is an incorrect implementation, since it does not separate the pure and impure parts of the monadic action. This module defines implementations for several common monad transformers.

Constructors

RunIO (forall b. m b -> IO (m b)) 

Extensible Exceptions

class (Typeable e, Show e) => Exception e

Instances

Exception IOException 
Exception SomeException 
Exception Deadlock 
Exception BlockedIndefinitelyOnSTM 
Exception BlockedIndefinitelyOnMVar 
Exception AsyncException 
Exception AssertionFailed 
Exception ArrayException 
Exception ErrorCall 
Exception ArithException 
Exception RecUpdError 
Exception RecSelError 
Exception RecConError 
Exception PatternMatchFail 
Exception NonTermination 
Exception NoMethodError 
Exception NestedAtomically 
Exception ExitCode 
Exception Interrupt 
Exception Dynamic 

data SomeException where

Constructors

SomeException :: Exception e => e -> SomeException