License | BSD |
---|---|

Maintainer | wren@community.haskell.org |

Stability | provisional |

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

Safe Haskell | Safe |

Language | Haskell98 |

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 :: Applicative m => MaybeKT m a -> m (Maybe a)
- toMaybeKT :: Applicative m => Maybe a -> MaybeKT m a
- liftMaybeK :: Applicative m => MaybeK a -> MaybeKT m a
- lowerMaybeK :: Applicative 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 Source | |

(Applicative m, Monad m) => MonadError () (MaybeKT m) Source | |

Monad (MaybeKT m) Source | |

Functor (MaybeKT m) Source | |

Applicative (MaybeKT m) Source | |

(Applicative m, Monad m) => Alternative (MaybeKT m) Source | |

(Applicative m, Monad m) => MonadPlus (MaybeKT m) Source |

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`

.