Portability | semi-portable (Rank2Types, MPTCs) |
---|---|

Stability | provisional |

Maintainer | wren@community.haskell.org |

Safe Haskell | Safe-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.

- data MaybeK a
- runMaybeK :: MaybeK a -> Maybe a
- toMaybeK :: Maybe a -> MaybeK a
- maybeK :: b -> (a -> b) -> MaybeK a -> b
- data MaybeKT m a
- runMaybeKT :: Monad m => MaybeKT m a -> m (Maybe a)
- toMaybeKT :: Monad m => Maybe a -> MaybeKT m a
- liftMaybeK :: Monad m => MaybeK a -> MaybeKT m a
- lowerMaybeK :: Monad m => MaybeKT m a -> m (MaybeK a)

# The partiality monad

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.

# The partiality monad transformer

A monad transformer version of `MaybeK`

.

MonadTrans MaybeKT | |

Monad m => MonadError () (MaybeKT m) | |

Monad (MaybeKT m) | |

Functor (MaybeKT m) | |

Monad m => MonadPlus (MaybeKT m) | |

Applicative (MaybeKT m) | |

Monad m => Alternative (MaybeKT m) |

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

Execute a `MaybeKT`

and return the concrete `Maybe`

encoding.

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`

.