Safe Haskell | Safe-Inferred |
---|---|

Language | Haskell2010 |

- class TotalIf a b c where
- decide :: a -> Decision b c

- class PartialIf a b where
- indicate :: a -> Indication b

- ifElse :: TotalIf a b c => a -> (b -> d) -> (c -> d) -> d
- inCase :: PartialIf a b => a -> (b -> c) -> c -> c
- ensure :: (Monad m, MonadPlus m, PartialIf a b) => a -> m b
- ensurePositive :: forall m a b c u. (Monad m, MonadPlus m, TotalIf a b c) => a -> u c -> m b
- ensureNegative :: forall m a b c u. (Monad m, MonadPlus m, TotalIf a b c) => a -> u b -> m c

# Documentation

class TotalIf a b c where Source

Instances of this class provide a test on some type a with an alternative case for when it fails. If it passes, it gives a value of type b; otherwise, it gives a value of type c.

class PartialIf a b where Source

Instances of this class provide a test on some type a. If it passes, it gives a value of type b; otherwise, it gives Nothing.

ifElse :: TotalIf a b c => a -> (b -> d) -> (c -> d) -> d Source

A conditional using a TotalIf instance. This is just like the
function `either`

which decomposes an Either, except that the Either
is produced through a TotalIf instance determined by the types of
the cases.

inCase :: PartialIf a b => a -> (b -> c) -> c -> c Source

A conditional using a PartialIf instance. This is just like the
function `maybe`

which decomposes a Maybe, except that the Maybe
is produced through an PartialIf instance determined by the type of
the positive case.

ensure :: (Monad m, MonadPlus m, PartialIf a b) => a -> m b Source

Like `guard`

but with a bonus: if the condition passes, you actually get
a hold of some new information.