Safe Haskell | None |
---|---|

Language | Haskell2010 |

This module allows the use of the Applicative Do extension with constrained monads.

- class Applicative f => Monad f where
- type Suitable f a :: Constraint

- class Monad f => MonadFail f where
- newtype Codensity f a = Codensity {
- runCodensity :: forall b. Suitable f b => (a -> f b) -> f b

- newtype ConstrainedWrapper f a = ConstrainedWrapper {
- unwrapConstrained :: Unconstrained f a

- return :: Applicative f => a -> f a
- ifThenElse :: Bool -> a -> a -> a
- (>>) :: Applicative f => f a -> f b -> f b
- type Initial = Ap
- type Final = Ap
- class FreeApplicative ap f where

# Documentation

class Applicative f => Monad f where Source #

This class is for types which have no constraints on their applicative
operations, but *do* have constraints on the monadic operations.

Most types which can conform are just standard unconstrained monads, with
the exception of the free applicative. The type

is an applicative
for `Ap`

f a*any* `f`

. However, it can only be made a monad by interpreting the
underlying type (which may be constrained), running the monadic operation,
and then lifting the result. In practice, this allows you to write code on
on the `Ap`

type, using applicative do notation, and have it be interpreted
correctly.

For instance, take the following expression:

example = do x <- pure 1 y <- pure 2 pure (x + y)

With the standard constrained monad module, you can instantiate that at
any type which is a constrained monad. `Set`

, for instance. However,
if `-XApplicativeDo`

is turned on, you will get the error:

No instance for (`Ord`

(`Integer`

->`Set`

`Integer`

))

The solution is to use

instead, which has the same
constraints on expressions built with `Ap`

`Set`

`<*>`

as those built with `>>=`

.

type Suitable f a :: Constraint Source #

Monad [] Source # | |

Monad Maybe Source # | |

Monad IO Source # | |

Monad Identity Source # | |

Monad Seq Source # | |

Monad ((->) b) Source # | |

Monad (Either e) Source # | |

Monoid m => Monad ((,) m) Source # | |

Monad m => Monad (MaybeT m) Source # | |

Monad f => Monad (ConstrainedWrapper f) Source # | |

Monad f => Monad (Codensity f) Source # | |

Monad f => Monad (Final f) Source # | |

Monad f => Monad (Initial f) Source # | |

Monad m => Monad (IdentityT * m) Source # | |

Monad m => Monad (ExceptT e m) Source # | |

Monad m => Monad (StateT s m) Source # | |

Monad m => Monad (StateT s m) Source # | |

Monad (ContT * r m) Source # | |

Monad m => Monad (ReaderT * s m) Source # | |

class Monad f => MonadFail f where Source #

See here for more details.

MonadFail [] Source # | |

MonadFail Maybe Source # | |

MonadFail IO Source # | |

MonadFail Seq Source # | |

IsString a => MonadFail (Either a) Source # | |

Monad m => MonadFail (MaybeT m) Source # | |

MonadFail m => MonadFail (IdentityT * m) Source # | |

(Monad m, IsString e) => MonadFail (ExceptT e m) Source # | |

MonadFail m => MonadFail (ReaderT * r m) Source # | |

newtype ConstrainedWrapper f a Source #

Applicative f => FreeApplicative ConstrainedWrapper f Source # | |

Applicative f => Functor (ConstrainedWrapper f) Source # | |

Applicative f => Applicative (ConstrainedWrapper f) Source # | |

Monad f => Monad (ConstrainedWrapper f) Source # | |

type Suitable (ConstrainedWrapper f) a Source # | |

return :: Applicative f => a -> f a Source #

An alias for `pure`

ifThenElse :: Bool -> a -> a -> a Source #

Function to which the `if ... then ... else`

syntax desugars to

(>>) :: Applicative f => f a -> f b -> f b infixl 1 Source #

Sequence two actions, discarding the result of the first. Alias for
`(`

.`*>`

)

class FreeApplicative ap f where Source #

Applicative f => FreeApplicative ConstrainedWrapper f Source # | |

Monad f => FreeApplicative Codensity f Source # | |

Applicative f => FreeApplicative Final f Source # | |

Applicative f => FreeApplicative Initial f Source # | |