kure-2.18.6: Combinators for Strategic Programming
Copyright(c) 2012--2021 The University of Kansas
LicenseBSD3
MaintainerNeil Sculthorpe <neil.sculthorpe@ntu.ac.uk>
Stabilitybeta
Portabilityghc
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.KURE.MonadCatch

Description

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

Synopsis

Monads with a Catch

class MonadFail m => MonadCatch m where Source #

Monads with a catch for fail. The following laws are expected to hold:

fail msg `catchM` f == f msg
return a `catchM` f == return a

Methods

catchM :: m a -> (String -> m a) -> m a Source #

Catch a failing monadic computation.

Instances

Instances details
MonadCatch IO Source #

The String is generated by showing the exception.

Instance details

Defined in Language.KURE.MonadCatch

Methods

catchM :: IO a -> (String -> IO a) -> IO a Source #

MonadCatch KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

catchM :: KureM a -> (String -> KureM a) -> KureM a Source #

MonadCatch m => MonadCatch (OneR m) Source # 
Instance details

Defined in Language.KURE.Combinators.Transform

Methods

catchM :: OneR m a -> (String -> OneR m a) -> OneR m a Source #

MonadCatch m => MonadCatch (AnyR m) Source # 
Instance details

Defined in Language.KURE.Combinators.Transform

Methods

catchM :: AnyR m a -> (String -> AnyR m a) -> AnyR m a Source #

MonadCatch m => MonadCatch (Transform c m a) Source #

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

Instance details

Defined in Language.KURE.Transform

Methods

catchM :: Transform c m a a0 -> (String -> Transform c m a a0) -> Transform c m a a0 Source #

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, except that it supports a MonadCatch instance which Either String does not (because its fail method calls error) A major advantage of this is that monadic pattern match failures are caught safely.

Instances

Instances details
Monad KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

(>>=) :: KureM a -> (a -> KureM b) -> KureM b #

(>>) :: KureM a -> KureM b -> KureM b #

return :: a -> KureM a #

Functor KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

fmap :: (a -> b) -> KureM a -> KureM b #

(<$) :: a -> KureM b -> KureM a #

MonadFail KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

fail :: String -> KureM a #

Applicative KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

pure :: a -> KureM a #

(<*>) :: KureM (a -> b) -> KureM a -> KureM b #

liftA2 :: (a -> b -> c) -> KureM a -> KureM b -> KureM c #

(*>) :: KureM a -> KureM b -> KureM b #

(<*) :: KureM a -> KureM b -> KureM a #

MonadCatch KureM Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

catchM :: KureM a -> (String -> KureM a) -> KureM a Source #

Eq a => Eq (KureM a) Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

(==) :: KureM a -> KureM a -> Bool #

(/=) :: KureM a -> KureM a -> Bool #

Show a => Show (KureM a) Source # 
Instance details

Defined in Language.KURE.MonadCatch

Methods

showsPrec :: Int -> KureM a -> ShowS #

show :: KureM a -> String #

showList :: [KureM a] -> ShowS #

runKureM :: (a -> b) -> (String -> b) -> KureM a -> b Source #

Eliminator for KureM.

fromKureM :: (String -> a) -> KureM a -> a Source #

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

liftKureM :: MonadFail m => KureM a -> m a Source #

Lift a KureM computation to any other monad.

The IO Monad

liftAndCatchIO :: (MonadCatch m, MonadIO m) => IO a -> m a Source #

Lift a computation from the IO monad, catching failures in the target monad.

Combinators

(<+) :: MonadCatch m => m a -> m a -> m a infixl 3 Source #

A monadic catch that ignores the error message.

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

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

tryM :: MonadCatch m => a -> m a -> m a Source #

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

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

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 Bool Source #

Determine if a monadic computation succeeds.

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

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

modFailMsg :: MonadCatch m => (String -> String) -> m a -> m a Source #

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

setFailMsg :: MonadCatch m => String -> m a -> m a Source #

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

prefixFailMsg :: MonadCatch m => String -> m a -> m a Source #

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

withPatFailMsg :: MonadCatch m => String -> m a -> m a Source #

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