unification-fd-0.11.0: Simple generic unification algorithms.
LicenseBSD
Maintainerwren@community.haskell.org
Stabilityprovisional
Portabilitysemi-portable (CPP, Rank2Types, MPTCs)
Safe HaskellSafe-Inferred
LanguageHaskell98

Control.Monad.MaybeK

Description

A continuation-passing variant of Maybe for short-circuiting at failure. This is based largely on code from the Haskell Wiki (http://www.haskell.org/haskellwiki/Performance/Monads) which was released under a simple permissive license (http://www.haskell.org/haskellwiki/HaskellWiki:Copyrights). However, various changes and extensions have been made, which are subject to the BSD license of this package.

Synopsis

The partiality monad

data MaybeK a Source #

A continuation-passing encoding of Maybe; also known as Codensity Maybe, if you're familiar with that terminology. N.B., this is not the 2-continuation implementation based on the Church encoding of Maybe. The latter tends to have worse performance than non-continuation based implementations.

This is generally more efficient than using Maybe for two reasons. First is that it right associates all binds, ensuring that bad associativity doesn't artificially introduce midpoints in short-circuiting to the nearest handler. Second is that it removes the need for intermediate case expressions.

N.B., the Alternative and MonadPlus instances are left-biased in a. Thus, they are not commutative.

Instances

Instances details
Monad MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

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

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

return :: a -> MaybeK a #

Functor MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

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

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

Applicative MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

pure :: a -> MaybeK a #

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

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

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

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

Alternative MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

empty :: MaybeK a #

(<|>) :: MaybeK a -> MaybeK a -> MaybeK a #

some :: MaybeK a -> MaybeK [a] #

many :: MaybeK a -> MaybeK [a] #

MonadPlus MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

mzero :: MaybeK a #

mplus :: MaybeK a -> MaybeK a -> MaybeK a #

MonadError () MaybeK Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

throwError :: () -> MaybeK a #

catchError :: MaybeK a -> (() -> MaybeK a) -> MaybeK a #

runMaybeK :: MaybeK a -> Maybe a Source #

Execute the MaybeK and return the concrete Maybe encoding.

toMaybeK :: Maybe a -> MaybeK a Source #

Lift a Maybe into MaybeK.

maybeK :: b -> (a -> b) -> MaybeK a -> b Source #

A version of maybe for convenience. This is almost identical to mplus but allows applying a continuation to Just values as well as handling Nothing errors. If you only want to handle the errors, use mplus instead.

The partiality monad transformer

data MaybeKT m a Source #

A monad transformer version of MaybeK.

Instances

Instances details
MonadTrans MaybeKT Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

lift :: Monad m => m a -> MaybeKT m a #

(Applicative m, Monad m) => MonadError () (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

throwError :: () -> MaybeKT m a #

catchError :: MaybeKT m a -> (() -> MaybeKT m a) -> MaybeKT m a #

Monad (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

(>>=) :: MaybeKT m a -> (a -> MaybeKT m b) -> MaybeKT m b #

(>>) :: MaybeKT m a -> MaybeKT m b -> MaybeKT m b #

return :: a -> MaybeKT m a #

Functor (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

fmap :: (a -> b) -> MaybeKT m a -> MaybeKT m b #

(<$) :: a -> MaybeKT m b -> MaybeKT m a #

Applicative (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

pure :: a -> MaybeKT m a #

(<*>) :: MaybeKT m (a -> b) -> MaybeKT m a -> MaybeKT m b #

liftA2 :: (a -> b -> c) -> MaybeKT m a -> MaybeKT m b -> MaybeKT m c #

(*>) :: MaybeKT m a -> MaybeKT m b -> MaybeKT m b #

(<*) :: MaybeKT m a -> MaybeKT m b -> MaybeKT m a #

(Applicative m, Monad m) => Alternative (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

empty :: MaybeKT m a #

(<|>) :: MaybeKT m a -> MaybeKT m a -> MaybeKT m a #

some :: MaybeKT m a -> MaybeKT m [a] #

many :: MaybeKT m a -> MaybeKT m [a] #

(Applicative m, Monad m) => MonadPlus (MaybeKT m) Source # 
Instance details

Defined in Control.Monad.MaybeK

Methods

mzero :: MaybeKT m a #

mplus :: MaybeKT m a -> MaybeKT m a -> MaybeKT m a #

runMaybeKT :: Applicative m => MaybeKT m a -> m (Maybe a) Source #

Execute a MaybeKT and return the concrete Maybe encoding.

toMaybeKT :: Applicative m => Maybe a -> MaybeKT m a Source #

Lift a Maybe into an MaybeKT.

liftMaybeK :: Applicative m => MaybeK a -> MaybeKT m a Source #

Lift an MaybeK into an MaybeKT.

lowerMaybeK :: Applicative m => MaybeKT m a -> m (MaybeK a) Source #

Lower an MaybeKT into an MaybeK.