Description

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

Synopsis

# 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 Ap f a is an applicative for 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 Ap Set instead, which has the same constraints on expressions built with <*> as those built with >>=.

Minimal complete definition

Associated Types

type Suitable f a :: Constraint Source #

Methods

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

join :: Suitable f a => f (f a) -> f a Source #

Instances

See here for more details.

Minimal complete definition

fail

Methods

fail :: Suitable f a => String -> f a Source #

Called when a pattern match fails in do-notation.

Instances

newtype Codensity f a Source #

Constructors

 Codensity FieldsrunCodensity :: forall b. Suitable f b => (a -> f b) -> f b

Instances

 Source # MethodsliftAp :: f a -> Codensity f a Source #retractAp :: Suitable f a => Codensity f a -> f a Source # Source # Methodsfmap :: (a -> b) -> Codensity f a -> Codensity f b #(<$) :: a -> Codensity f b -> Codensity f a # Source # Methodspure :: a -> Codensity f a #(<*>) :: Codensity f (a -> b) -> Codensity f a -> Codensity f b #(*>) :: Codensity f a -> Codensity f b -> Codensity f b #(<*) :: Codensity f a -> Codensity f b -> Codensity f a # Monad f => Monad (Codensity f) Source # Associated Typestype Suitable (Codensity f :: * -> *) a :: Constraint Source # Methods(>>=) :: (Suitable (Codensity f) a, Suitable (Codensity f) b) => Codensity f a -> (a -> Codensity f b) -> Codensity f b Source #join :: Suitable (Codensity f) a => Codensity f (Codensity f a) -> Codensity f a Source # type Suitable (Codensity f) a Source # type Suitable (Codensity f) a = Suitable f a newtype ConstrainedWrapper f a Source # Constructors  ConstrainedWrapper FieldsunwrapConstrained :: Unconstrained f a Instances  Source # MethodsliftAp :: f a -> ConstrainedWrapper f a Source #retractAp :: Suitable f a => ConstrainedWrapper f a -> f a Source # Source # Methodsfmap :: (a -> b) -> ConstrainedWrapper f a -> ConstrainedWrapper f b #(<$) :: a -> ConstrainedWrapper f b -> ConstrainedWrapper f a # Source # Methodspure :: a -> ConstrainedWrapper f a #(<*>) :: ConstrainedWrapper f (a -> b) -> ConstrainedWrapper f a -> ConstrainedWrapper f b #(*>) :: ConstrainedWrapper f a -> ConstrainedWrapper f b -> ConstrainedWrapper f b #(<*) :: ConstrainedWrapper f a -> ConstrainedWrapper f b -> ConstrainedWrapper f a # Monad f => Monad (ConstrainedWrapper f) Source # Associated Typestype Suitable (ConstrainedWrapper f :: * -> *) a :: Constraint Source # Methods(>>=) :: (Suitable (ConstrainedWrapper f) a, Suitable (ConstrainedWrapper f) b) => ConstrainedWrapper f a -> (a -> ConstrainedWrapper f b) -> ConstrainedWrapper f b Source #join :: Suitable (ConstrainedWrapper f) a => ConstrainedWrapper f (ConstrainedWrapper f a) -> ConstrainedWrapper f a Source # type Suitable (ConstrainedWrapper f) a Source # type Suitable (ConstrainedWrapper f) a = (Suitable f a, Suitable f (f a))

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 (*>).

type Final = Ap Source #

class FreeApplicative ap f where Source #

Minimal complete definition

Methods

liftAp :: f a -> ap f a Source #

retractAp :: Suitable f a => ap f a -> f a Source #

Instances

 Source # MethodsliftAp :: f a -> ConstrainedWrapper f a Source #retractAp :: Suitable f a => ConstrainedWrapper f a -> f a Source # Source # MethodsliftAp :: f a -> Codensity f a Source #retractAp :: Suitable f a => Codensity f a -> f a Source # Source # MethodsliftAp :: f a -> Final f a Source #retractAp :: Suitable f a => Final f a -> f a Source # Source # MethodsliftAp :: f a -> Initial f a Source #retractAp :: Suitable f a => Initial f a -> f a Source #