unification-fd-0.7.0: Simple generic unification algorithms.

Portabilitysemi-portable (Rank2Types, MPTCs)
Safe HaskellSafe-Infered




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.


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 aSource

Execute the MaybeK and return the concrete Maybe encoding.

toMaybeK :: Maybe a -> MaybeK aSource

Lift a Maybe into MaybeK.

maybeK :: b -> (a -> b) -> MaybeK a -> bSource

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 aSource

Lift a Maybe into an MaybeKT.

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

Lift an MaybeK into an MaybeKT.

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

Lower an MaybeKT into an MaybeK.