kure-2.8.0: Combinators for Strategic Programming

Portabilityghc
Stabilitybeta
MaintainerNeil Sculthorpe <neil@ittc.ku.edu>
Safe HaskellSafe-Inferred

Language.KURE.MonadCatch

Contents

Description

This module provides classes for catch-like operations on Monads.

Synopsis

Monads with a Catch

class Monad m => MonadCatch m whereSource

Monads with a catch for fail. The following law is expected to hold:

 fail msg `catchM` f == f msg

Methods

catchM :: m a -> (String -> m a) -> m aSource

Catch a failing monadic computation.

Instances

MonadCatch KureM 
MonadCatch m => MonadCatch (OneR m) 
MonadCatch m => MonadCatch (AnyR m) 
MonadCatch m => MonadCatch (Translate c m a)

Lifting through a Reader transformer, where (c,a) is the read-only environment.

The KURE Monad

data KureM a Source

KureM is the minimal structure that can be an instance of MonadCatch. The KURE user is free to either use KureM or provide their own monad. KureM is essentially the same as (Either String a), except that the fail method produces an error in the monad, rather than invoking error. A major advantage of this is that monadic pattern match failures are caught safely.

runKureM :: (a -> b) -> (String -> b) -> KureM a -> bSource

Eliminator for KureM.

fromKureM :: (String -> a) -> KureM a -> aSource

Get the value from a KureM, providing a function to handle the error case.

Combinators

(<+) :: MonadCatch m => m a -> m a -> m aSource

A monadic catch that ignores the error message.

catchesM :: (Foldable f, MonadCatch m) => f (m a) -> m aSource

Select the first monadic computation that succeeds, discarding any thereafter.

tryM :: MonadCatch m => a -> m a -> m aSource

Catch a failing monadic computation, making it succeed with a constant value.

mtryM :: (MonadCatch m, Monoid a) => m a -> m aSource

Catch a failing monadic computation, making it succeed with mempty.

attemptM :: MonadCatch m => m a -> m (Either String a)Source

Catch a failing monadic computation, making it succeed with an error message.

testM :: MonadCatch m => m a -> m BoolSource

Determine if a monadic computation succeeds.

notM :: MonadCatch m => m a -> m ()Source

Fail if the Monad succeeds; succeed with () if it fails.

modFailMsg :: MonadCatch m => (String -> String) -> m a -> m aSource

Modify the error message of a failing monadic computation. Successful computations are unaffected.

setFailMsg :: MonadCatch m => String -> m a -> m aSource

Set the error message of a failing monadic computation. Successful computations are unaffected.

prefixFailMsg :: MonadCatch m => String -> m a -> m aSource

Add a prefix to the error message of a failing monadic computation. Successful computations are unaffected.

withPatFailMsg :: MonadCatch m => String -> m a -> m aSource

Use the given error message whenever a monadic pattern match failure occurs.