unification-fd-0.9.0: Simple generic unification algorithms.

LicenseBSD
Maintainerwren@community.haskell.org
Stabilityprovisional
Portabilitysemi-portable (Rank2Types, MPTCs)
Safe HaskellSafe-Inferred
LanguageHaskell98

Control.Monad.MaybeK

Contents

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.

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.

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

Execute a MaybeKT and return the concrete Maybe encoding.

toMaybeKT :: Monad m => Maybe a -> MaybeKT m a Source

Lift a Maybe into an MaybeKT.

liftMaybeK :: Monad m => MaybeK a -> MaybeKT m a Source

Lift an MaybeK into an MaybeKT.

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

Lower an MaybeKT into an MaybeK.