Control.Selective

selective-0.7.0.1: Selective applicative functors

Copyright | (c) Andrey Mokhov 2018-2024
License | MIT (see the file LICENSE)
Maintainer | andrey.mokhov@gmail.com
Stability | experimental
Safe Haskell | None
Language | Haskell2010

Control.Selective

Contents

- Type class
- Conditional combinators
- Selective functors
- Miscellaneous

Description

This is a library for selective applicative functors, or just selective functors for short, an abstraction between applicative functors and monads, introduced in this paper: https://dl.acm.org/doi/10.1145/3341694.

Synopsis

- class Applicative f => Selective (f :: Type -> Type) where
  - select :: f (Either a b) -> f (a -> b) -> f b
- (<*?) :: Selective f => f (Either a b) -> f (a -> b) -> f b
- branch :: Selective f => f (Either a b) -> f (a -> c) -> f (b -> c) -> f c
- selectA :: Applicative f => f (Either a b) -> f (a -> b) -> f b
- selectT :: Traversable f => f (Either a b) -> f (a -> b) -> f b
- apS :: Selective f => f (a -> b) -> f a -> f b
- selectM :: Monad f => f (Either a b) -> f (a -> b) -> f b
- ifS :: Selective f => f Bool -> f a -> f a -> f a
- whenS :: Selective f => f Bool -> f () -> f ()
- fromMaybeS :: Selective f => f a -> f (Maybe a) -> f a
- orElse :: (Selective f, Semigroup e) => f (Either e a) -> f (Either e a) -> f (Either e a)
- andAlso :: (Selective f, Semigroup a) => f (Either e a) -> f (Either e a) -> f (Either e a)
- untilRight :: (Monoid a, Selective f) => f (Either a b) -> f (a, b)
- whileS :: Selective f => f Bool -> f ()
- (<||>) :: Selective f => f Bool -> f Bool -> f Bool
- (<&&>) :: Selective f => f Bool -> f Bool -> f Bool
- foldS :: (Selective f, Foldable t, Monoid a) => t (f (Either e a)) -> f (Either e a)
- anyS :: Selective f => (a -> f Bool) -> [a] -> f Bool
- allS :: Selective f => (a -> f Bool) -> [a] -> f Bool
- bindS :: (Bounded a, Enum a, Eq a, Selective f) => f a -> (a -> f b) -> f b
- data Cases a
- casesEnum :: (Bounded a, Enum a) => Cases a
- cases :: Eq a => [a] -> Cases a
- matchS :: (Eq a, Selective f) => Cases a -> f a -> (a -> f b) -> f (Either a b)
- matchM :: Monad m => Cases a -> m a -> (a -> m b) -> m (Either a b)
- newtype SelectA (f :: Type -> Type) a = SelectA {
  - getSelectA :: f a
  }
- newtype SelectM (f :: Type -> Type) a = SelectM {
  - getSelectM :: f a
  }
- newtype Over m a = Over {
  - getOver :: m
  }
- newtype Under m a = Under {
  - getUnder :: m
  }
- data Validation e a
  - = Failure e
  - | Success a
- swapEither :: Either a b -> Either b a
- newtype ComposeEither (f :: Type -> Type) e a = ComposeEither (f (Either e a))
- newtype ComposeTraversable (f :: Type -> Type) (g :: Type -> Type) a = ComposeTraversable (f (g a))

# Type class

class Applicative f => Selective (f :: Type -> Type) where #

Selective applicative functors. You can think of `select` as a selective function application: when given a value of type `Left` `a`, you must apply the given function, but when given a `Right` `b`, you may skip the function and associated effects, and simply return the `b`.

Note that it is not a requirement for selective functors to skip unnecessary effects. It may be counterintuitive, but this makes them more useful. Why? Typically, when executing a selective computation, you would want to skip the effects (saving work); but on the other hand, if your goal is to statically analyse a given selective computation and extract the set of all possible effects (without actually executing them), then you do not want to skip any effects, because that defeats the purpose of static analysis.

The type signature of `select` is reminiscent of both `<*>` and `>>=`, and indeed a selective functor is in some sense a composition of an applicative functor and the `Either` monad.

Laws:

- Identity:

    x <*? pure id = either id id <$> x

- Distributivity; note that `y` and `z` have the same type `f (a -> b)`:

    pure x <*? (y *> z) = (pure x <*? y) *> (pure x <*? z)

- Associativity:

    x <*? (y <*? z) = (f <$> x) <*? (g <$> y) <*? (h <$> z)
      where
        f x = Right <$> x
        g y = a -> bimap (,a) ($a) y
        h z = uncurry z

- Monadic `select` (for selective functors that are also monads):

    select = selectM

There are also a few useful theorems:

- Apply a pure function to the result:

    f <$> select x y = select (fmap f <$> x) (fmap f <$> y)

- Apply a pure function to the `Left` case of the first argument:

    select (first f <$> x) y = select x ((. f) <$> y)

- Apply a pure function to the second argument:

    select x (f <$> y) = select (first (flip f) <$> x) ((&) <$> y)

- Generalised identity:

    x <*? pure y = either y id <$> x

- A selective functor is rigid if it satisfies `<*>` `=` `apS`. The following interchange law holds for rigid selective functors:

    x *> (y <*? z) = (x *> y) <*? z

If f is also a `Monad`, we require that `select` = `selectM`, from which one can prove `<*>` `=` `apS`.

Methods

select :: f (Either a b) -> f (a -> b) -> f b #

#### Instances

Instances details

Selective NonEmpty # |
Instance details Defined in Control.Selective Methods select :: NonEmpty (Either a b) -> NonEmpty (a -> b) -> NonEmpty b #
Selective STM # |
Instance details Defined in Control.Selective Methods select :: STM (Either a b) -> STM (a -> b) -> STM b #
Selective Identity # |
Instance details Defined in Control.Selective Methods select :: Identity (Either a b) -> Identity (a -> b) -> Identity b #
Selective ZipList # |
Instance details Defined in Control.Selective Methods select :: ZipList (Either a b) -> ZipList (a -> b) -> ZipList b #
Selective IO # |
Instance details Defined in Control.Selective Methods select :: IO (Either a b) -> IO (a -> b) -> IO b #
Selective Maybe # |
Instance details Defined in Control.Selective Methods select :: Maybe (Either a b) -> Maybe (a -> b) -> Maybe b #
Selective [] # |
Instance details Defined in Control.Selective Methods select :: [Either a b] -> [a -> b] -> [b] #
ArrowChoice a => Selective (ArrowMonad a) # |
Instance details Defined in Control.Selective Methods select :: ArrowMonad a (Either a0 b) -> ArrowMonad a (a0 -> b) -> ArrowMonad a b #
Selective (Either e) # |
Instance details Defined in Control.Selective Methods select :: Either e (Either a b) -> Either e (a -> b) -> Either e b #
Selective (Proxy :: Type -> Type) # |
Instance details Defined in Control.Selective Methods select :: Proxy (Either a b) -> Proxy (a -> b) -> Proxy b #
Selective (ST s) # |
Instance details Defined in Control.Selective Methods select :: ST s (Either a b) -> ST s (a -> b) -> ST s b #
Monoid m => Selective (Over m) # |
Instance details Defined in Control.Selective Methods select :: Over m (Either a b) -> Over m (a -> b) -> Over m b #
Applicative f => Selective (SelectA f) # |
Instance details Defined in Control.Selective Methods select :: SelectA f (Either a b) -> SelectA f (a -> b) -> SelectA f b #
Monad f => Selective (SelectM f) # |
Instance details Defined in Control.Selective Methods select :: SelectM f (Either a b) -> SelectM f (a -> b) -> SelectM f b #
Monoid m => Selective (Under m) # |
Instance details Defined in Control.Selective Methods select :: Under m (Either a b) -> Under m (a -> b) -> Under m b #
Semigroup e => Selective (Validation e) # |
Instance details Defined in Control.Selective Methods select :: Validation e (Either a b) -> Validation e (a -> b) -> Validation e b #
Selective (Select f) # |
Instance details Defined in Control.Selective.Free Methods select :: Select f (Either a b) -> Select f (a -> b) -> Select f b #
Functor f => Selective (Select f) # |
Instance details Defined in Control.Selective.Rigid.Free Methods select :: Select f (Either a b) -> Select f (a -> b) -> Select f b #
Selective (Select f) # |
Instance details Defined in Control.Selective.Rigid.Freer Methods select :: Select f (Either a b) -> Select f (a -> b) -> Select f b #
Selective f => Selective (Lift f) # |
Instance details Defined in Control.Selective Methods select :: Lift f (Either a b) -> Lift f (a -> b) -> Lift f b #
Monad m => Selective (MaybeT m) # |
Instance details Defined in Control.Selective Methods select :: MaybeT m (Either a b) -> MaybeT m (a -> b) -> MaybeT m b #
Monoid a => Selective ((,) a) # |
Instance details Defined in Control.Selective Methods select :: (a, Either a0 b) -> (a, a0 -> b) -> (a, b) #
Selective f => Selective (ComposeEither f e) # |
Instance details Defined in Control.Selective Methods select :: ComposeEither f e (Either a b) -> ComposeEither f e (a -> b) -> ComposeEither f e b #
(Selective f, Applicative g, Traversable g) => Selective (ComposeTraversable f g) # |
Instance details Defined in Control.Selective Methods select :: ComposeTraversable f g (Either a b) -> ComposeTraversable f g (a -> b) -> ComposeTraversable f g b #
Selective f => Selective (ExceptT e f) # |
Instance details Defined in Control.Selective.Trans.Except Methods select :: ExceptT e f (Either a b) -> ExceptT e f (a -> b) -> ExceptT e f b #
Selective f => Selective (IdentityT f) # |
Instance details Defined in Control.Selective Methods select :: IdentityT f (Either a b) -> IdentityT f (a -> b) -> IdentityT f b #
Selective f => Selective (ReaderT env f) # |
Instance details Defined in Control.Selective Methods select :: ReaderT env f (Either a b) -> ReaderT env f (a -> b) -> ReaderT env f b #
Monad m => Selective (StateT s m) # |
Instance details Defined in Control.Selective Methods select :: StateT s m (Either a b) -> StateT s m (a -> b) -> StateT s m b #
Monad m => Selective (StateT s m) # |
Instance details Defined in Control.Selective Methods select :: StateT s m (Either a b) -> StateT s m (a -> b) -> StateT s m b #
(Monoid w, Selective f) => Selective (WriterT w f) # |
Instance details Defined in Control.Selective Methods select :: WriterT w f (Either a b) -> WriterT w f (a -> b) -> WriterT w f b #
(Monoid w, Selective f) => Selective (WriterT w f) # |
Instance details Defined in Control.Selective Methods select :: WriterT w f (Either a b) -> WriterT w f (a -> b) -> WriterT w f b #
(Selective f, Selective g) => Selective (Product f g) # |
Instance details Defined in Control.Selective Methods select :: Product f g (Either a b) -> Product f g (a -> b) -> Product f g b #
Selective (ContT r m) # |
Instance details Defined in Control.Selective Methods select :: ContT r m (Either a b) -> ContT r m (a -> b) -> ContT r m b #
Selective ((->) a) # |
Instance details Defined in Control.Selective Methods select :: (a -> Either a0 b) -> (a -> (a0 -> b)) -> a -> b #
(Applicative f, Selective g) => Selective (Compose f g) # |
Instance details Defined in Control.Selective Methods select :: Compose f g (Either a b) -> Compose f g (a -> b) -> Compose f g b #
(Monoid w, Monad m) => Selective (RWST r w s m) # |
Instance details Defined in Control.Selective Methods select :: RWST r w s m (Either a b) -> RWST r w s m (a -> b) -> RWST r w s m b #
(Monoid w, Monad m) => Selective (RWST r w s m) # |
Instance details Defined in Control.Selective Methods select :: RWST r w s m (Either a b) -> RWST r w s m (a -> b) -> RWST r w s m b #

(<*?) :: Selective f => f (Either a b) -> f (a -> b) -> f b infixl 4 #

An operator alias for `select`, which is sometimes convenient. It tries to follow the notational convention for `Applicative` operators. The angle bracket pointing to the left means we always use the corresponding value. The value on the right, however, may be skipped, hence the question mark.

branch :: Selective f => f (Either a b) -> f (a -> c) -> f (b -> c) -> f c #

The `branch` function is a natural generalisation of `select`: instead of skipping an unnecessary effect, it chooses which of the two given effectful functions to apply to a given argument; the other effect is unnecessary. It is possible to implement `branch` in terms of `select`, which is a good puzzle (give it a try!).

We can also implement `select` via `branch`:

    selectB :: Selective f => f (Either a b) -> f (a -> b) -> f b
    selectB x y = branch x y (pure id)

selectA :: Applicative f => f (Either a b) -> f (a -> b) -> f b #

We can write a function with the type signature of `select` using the `Applicative` type class, but it will always execute the effects associated with the second argument, hence being potentially less efficient.

selectT :: Traversable f => f (Either a b) -> f (a -> b) -> f b #

For traversable functors, we can implement `select` in another interesting way: the effects associated with the second argument can be skipped as long as the first argument contains only `Right` values.

apS :: Selective f => f (a -> b) -> f a -> f b #

Recover the application operator `<*>` from `select`. Rigid selective functors satisfy the law `<*>` `=` `apS` and furthermore, the resulting applicative functor satisfies all laws of `Applicative`:

- Identity:

      pure id <*> v = v

- Homomorphism:

      pure f <*> pure x = pure (f x)

- Interchange:

      u <*> pure y = pure ($y) <*> u

- Composition:

      (.) <$> u <*> v <*> w = u <*> (v <*> w)

selectM :: Monad f => f (Either a b) -> f (a -> b) -> f b #

One can easily implement a monadic `selectM` that satisfies the laws, hence any `Monad` is `Selective`.

# Conditional combinators

ifS :: Selective f => f Bool -> f a -> f a -> f a #

Branch on a Boolean value, skipping unnecessary effects.

whenS :: Selective f => f Bool -> f () -> f () #

Conditionally perform an effect.

fromMaybeS :: Selective f => f a -> f (Maybe a) -> f a #

A lifted version of `fromMaybe`.

orElse :: (Selective f, Semigroup e) => f (Either e a) -> f (Either e a) -> f (Either e a) #

Return the first `Right` value. If both are `Left`'s, accumulate errors.

andAlso :: (Selective f, Semigroup a) => f (Either e a) -> f (Either e a) -> f (Either e a) #

Accumulate the `Right` values, or return the first `Left`.

untilRight :: (Monoid a, Selective f) => f (Either a b) -> f (a, b) #

Keep running an effectful computation until it returns a `Right` value, collecting the `Left`'s using a supplied `Monoid` instance.

whileS :: Selective f => f Bool -> f () #

Keep checking an effectful condition while it holds.

(<||>) :: Selective f => f Bool -> f Bool -> f Bool #

A lifted version of lazy Boolean OR.

(<&&>) :: Selective f => f Bool -> f Bool -> f Bool #

A lifted version of lazy Boolean AND.

foldS :: (Selective f, Foldable t, Monoid a) => t (f (Either e a)) -> f (Either e a) #

Generalised folding with the short-circuiting behaviour.

anyS :: Selective f => (a -> f Bool) -> [a] -> f Bool #

A lifted version of `any`. Retains the short-circuiting behaviour.

allS :: Selective f => (a -> f Bool) -> [a] -> f Bool #

A lifted version of `all`. Retains the short-circuiting behaviour.

bindS :: (Bounded a, Enum a, Eq a, Selective f) => f a -> (a -> f b) -> f b #

A restricted version of monadic bind. Fails with an error if the `Bounded` and `Enum` instances for `a` do not cover all values of `a`.

data Cases a #

A list of values, equipped with a fast membership test.

casesEnum :: (Bounded a, Enum a) => Cases a #

The list of all possible values of an enumerable data type.

cases :: Eq a => [a] -> Cases a #

Embed a list of values into `Cases` using the trivial but slow membership test based on `elem`.

matchS :: (Eq a, Selective f) => Cases a -> f a -> (a -> f b) -> f (Either a b) #

Eliminate all specified values `a` from `f (Either a b)` by replacing each of them with a given `f a`.

matchM :: Monad m => Cases a -> m a -> (a -> m b) -> m (Either a b) #

Eliminate all specified values `a` from `f (Either a b)` by replacing each of them with a given `f a`.

# Selective functors

newtype SelectA (f :: Type -> Type) a #

Any applicative functor can be given a `Selective` instance by defining `select` `=` `selectA`. This data type captures this pattern, so you can use it in combination with the `DerivingVia` extension as follows:

    newtype Over m a = Over m
        deriving (Functor, Applicative, Selective) via SelectA (Const m)

Constructors

SelectA |
Fields getSelectA :: f a

#### Instances

Instances details

Applicative f => Applicative (SelectA f) # |
Instance details Defined in Control.Selective Methods pure :: a -> SelectA f a # (<*>) :: SelectA f (a -> b) -> SelectA f a -> SelectA f b # liftA2 :: (a -> b -> c) -> SelectA f a -> SelectA f b -> SelectA f c # (*>) :: SelectA f a -> SelectA f b -> SelectA f b # (<*) :: SelectA f a -> SelectA f b -> SelectA f a #
Functor f => Functor (SelectA f) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> SelectA f a -> SelectA f b # (<$) :: a -> SelectA f b -> SelectA f a #
Applicative f => Selective (SelectA f) # |
Instance details Defined in Control.Selective Methods select :: SelectA f (Either a b) -> SelectA f (a -> b) -> SelectA f b #

newtype SelectM (f :: Type -> Type) a #

Any monad can be given a `Selective` instance by defining `select` `=` `selectM`. This data type captures this pattern, so you can use it in combination with the `DerivingVia` extension as follows:

    newtype V1 a = V1 a
        deriving (Functor, Applicative, Selective, Monad) via SelectM Identity

Constructors

SelectM |
Fields getSelectM :: f a

#### Instances

Instances details

Applicative f => Applicative (SelectM f) # |
Instance details Defined in Control.Selective Methods pure :: a -> SelectM f a # (<*>) :: SelectM f (a -> b) -> SelectM f a -> SelectM f b # liftA2 :: (a -> b -> c) -> SelectM f a -> SelectM f b -> SelectM f c # (*>) :: SelectM f a -> SelectM f b -> SelectM f b # (<*) :: SelectM f a -> SelectM f b -> SelectM f a #
Functor f => Functor (SelectM f) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> SelectM f a -> SelectM f b # (<$) :: a -> SelectM f b -> SelectM f a #
Monad f => Monad (SelectM f) # |
Instance details Defined in Control.Selective Methods (>>=) :: SelectM f a -> (a -> SelectM f b) -> SelectM f b # (>>) :: SelectM f a -> SelectM f b -> SelectM f b # return :: a -> SelectM f a #
Monad f => Selective (SelectM f) # |
Instance details Defined in Control.Selective Methods select :: SelectM f (Either a b) -> SelectM f (a -> b) -> SelectM f b #

newtype Over m a #

Static analysis of selective functors with over-approximation.

Constructors

Over |
Fields getOver :: m

#### Instances

Instances details

Monoid m => Applicative (Over m) # |
Instance details Defined in Control.Selective Methods pure :: a -> Over m a # (<*>) :: Over m (a -> b) -> Over m a -> Over m b # liftA2 :: (a -> b -> c) -> Over m a -> Over m b -> Over m c # (*>) :: Over m a -> Over m b -> Over m b # (<*) :: Over m a -> Over m b -> Over m a #
Functor (Over m) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> Over m a -> Over m b # (<$) :: a -> Over m b -> Over m a #
Monoid m => Selective (Over m) # |
Instance details Defined in Control.Selective Methods select :: Over m (Either a b) -> Over m (a -> b) -> Over m b #
Show m => Show (Over m a) # |
Instance details Defined in Control.Selective Methods showsPrec :: Int -> Over m a -> ShowS # show :: Over m a -> String # showList :: [Over m a] -> ShowS #
Eq m => Eq (Over m a) # |
Instance details Defined in Control.Selective Methods (==) :: Over m a -> Over m a -> Bool # (/=) :: Over m a -> Over m a -> Bool #
Ord m => Ord (Over m a) # |
Instance details Defined in Control.Selective Methods compare :: Over m a -> Over m a -> Ordering # (<) :: Over m a -> Over m a -> Bool # (<=) :: Over m a -> Over m a -> Bool # (>) :: Over m a -> Over m a -> Bool # (>=) :: Over m a -> Over m a -> Bool # max :: Over m a -> Over m a -> Over m a # min :: Over m a -> Over m a -> Over m a #

newtype Under m a #

Static analysis of selective functors with under-approximation.

Constructors

Under |
Fields getUnder :: m

#### Instances

Instances details

Monoid m => Applicative (Under m) # |
Instance details Defined in Control.Selective Methods pure :: a -> Under m a # (<*>) :: Under m (a -> b) -> Under m a -> Under m b # liftA2 :: (a -> b -> c) -> Under m a -> Under m b -> Under m c # (*>) :: Under m a -> Under m b -> Under m b # (<*) :: Under m a -> Under m b -> Under m a #
Functor (Under m) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> Under m a -> Under m b # (<$) :: a -> Under m b -> Under m a #
Foldable (Under m) # |
Instance details Defined in Control.Selective Methods fold :: Monoid m0 => Under m m0 -> m0 # foldMap :: Monoid m0 => (a -> m0) -> Under m a -> m0 # foldMap' :: Monoid m0 => (a -> m0) -> Under m a -> m0 # foldr :: (a -> b -> b) -> b -> Under m a -> b # foldr' :: (a -> b -> b) -> b -> Under m a -> b # foldl :: (b -> a -> b) -> b -> Under m a -> b # foldl' :: (b -> a -> b) -> b -> Under m a -> b # foldr1 :: (a -> a -> a) -> Under m a -> a # foldl1 :: (a -> a -> a) -> Under m a -> a # toList :: Under m a -> [a] # null :: Under m a -> Bool # length :: Under m a -> Int # elem :: Eq a => a -> Under m a -> Bool # maximum :: Ord a => Under m a -> a # minimum :: Ord a => Under m a -> a # sum :: Num a => Under m a -> a # product :: Num a => Under m a -> a #
Traversable (Under m) # |
Instance details Defined in Control.Selective Methods traverse :: Applicative f => (a -> f b) -> Under m a -> f (Under m b) # sequenceA :: Applicative f => Under m (f a) -> f (Under m a) # mapM :: Monad m0 => (a -> m0 b) -> Under m a -> m0 (Under m b) # sequence :: Monad m0 => Under m (m0 a) -> m0 (Under m a) #
Monoid m => Selective (Under m) # |
Instance details Defined in Control.Selective Methods select :: Under m (Either a b) -> Under m (a -> b) -> Under m b #
Show m => Show (Under m a) # |
Instance details Defined in Control.Selective Methods showsPrec :: Int -> Under m a -> ShowS # show :: Under m a -> String # showList :: [Under m a] -> ShowS #
Eq m => Eq (Under m a) # |
Instance details Defined in Control.Selective Methods (==) :: Under m a -> Under m a -> Bool # (/=) :: Under m a -> Under m a -> Bool #
Ord m => Ord (Under m a) # |
Instance details Defined in Control.Selective Methods compare :: Under m a -> Under m a -> Ordering # (<) :: Under m a -> Under m a -> Bool # (<=) :: Under m a -> Under m a -> Bool # (>) :: Under m a -> Under m a -> Bool # (>=) :: Under m a -> Under m a -> Bool # max :: Under m a -> Under m a -> Under m a # min :: Under m a -> Under m a -> Under m a #

data Validation e a #

Selective instance for the standard applicative functor Validation. This is a good example of a non-trivial selective functor which is not a monad.

Constructors

Failure e |
Success a |

#### Instances

Instances details

Semigroup e => Applicative (Validation e) # |
Instance details Defined in Control.Selective Methods pure :: a -> Validation e a # (<*>) :: Validation e (a -> b) -> Validation e a -> Validation e b # liftA2 :: (a -> b -> c) -> Validation e a -> Validation e b -> Validation e c # (*>) :: Validation e a -> Validation e b -> Validation e b # (<*) :: Validation e a -> Validation e b -> Validation e a #
Functor (Validation e) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> Validation e a -> Validation e b # (<$) :: a -> Validation e b -> Validation e a #
Semigroup e => Selective (Validation e) # |
Instance details Defined in Control.Selective Methods select :: Validation e (Either a b) -> Validation e (a -> b) -> Validation e b #
(Show e, Show a) => Show (Validation e a) # |
Instance details Defined in Control.Selective Methods showsPrec :: Int -> Validation e a -> ShowS # show :: Validation e a -> String # showList :: [Validation e a] -> ShowS #
(Eq e, Eq a) => Eq (Validation e a) # |
Instance details Defined in Control.Selective Methods (==) :: Validation e a -> Validation e a -> Bool # (/=) :: Validation e a -> Validation e a -> Bool #
(Ord e, Ord a) => Ord (Validation e a) # |
Instance details Defined in Control.Selective Methods compare :: Validation e a -> Validation e a -> Ordering # (<) :: Validation e a -> Validation e a -> Bool # (<=) :: Validation e a -> Validation e a -> Bool # (>) :: Validation e a -> Validation e a -> Bool # (>=) :: Validation e a -> Validation e a -> Bool # max :: Validation e a -> Validation e a -> Validation e a # min :: Validation e a -> Validation e a -> Validation e a #

# Miscellaneous

swapEither :: Either a b -> Either b a #

Swap `Left` and `Right`.

newtype ComposeEither (f :: Type -> Type) e a #

Composition of a selective functor `f` with the `Either` monad.

Constructors

ComposeEither (f (Either e a)) |

#### Instances

Instances details

(Selective f, Monoid e) => Alternative (ComposeEither f e) # |
Instance details Defined in Control.Selective Methods empty :: ComposeEither f e a # (<|>) :: ComposeEither f e a -> ComposeEither f e a -> ComposeEither f e a # some :: ComposeEither f e a -> ComposeEither f e [a] # many :: ComposeEither f e a -> ComposeEither f e [a] #
Selective f => Applicative (ComposeEither f e) # |
Instance details Defined in Control.Selective Methods pure :: a -> ComposeEither f e a # (<*>) :: ComposeEither f e (a -> b) -> ComposeEither f e a -> ComposeEither f e b # liftA2 :: (a -> b -> c) -> ComposeEither f e a -> ComposeEither f e b -> ComposeEither f e c # (*>) :: ComposeEither f e a -> ComposeEither f e b -> ComposeEither f e b # (<*) :: ComposeEither f e a -> ComposeEither f e b -> ComposeEither f e a #
Functor f => Functor (ComposeEither f e) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> ComposeEither f e a -> ComposeEither f e b # (<$) :: a -> ComposeEither f e b -> ComposeEither f e a #
Selective f => Selective (ComposeEither f e) # |
Instance details Defined in Control.Selective Methods select :: ComposeEither f e (Either a b) -> ComposeEither f e (a -> b) -> ComposeEither f e b #

newtype ComposeTraversable (f :: Type -> Type) (g :: Type -> Type) a #

Composition of a selective functor `f` and an applicative traversable functor `g`.

Constructors

ComposeTraversable (f (g a)) |

#### Instances

Instances details

(Applicative f, Applicative g) => Applicative (ComposeTraversable f g) # |
Instance details Defined in Control.Selective Methods pure :: a -> ComposeTraversable f g a # (<*>) :: ComposeTraversable f g (a -> b) -> ComposeTraversable f g a -> ComposeTraversable f g b # liftA2 :: (a -> b -> c) -> ComposeTraversable f g a -> ComposeTraversable f g b -> ComposeTraversable f g c # (*>) :: ComposeTraversable f g a -> ComposeTraversable f g b -> ComposeTraversable f g b # (<*) :: ComposeTraversable f g a -> ComposeTraversable f g b -> ComposeTraversable f g a #
(Functor f, Functor g) => Functor (ComposeTraversable f g) # |
Instance details Defined in Control.Selective Methods fmap :: (a -> b) -> ComposeTraversable f g a -> ComposeTraversable f g b # (<$) :: a -> ComposeTraversable f g b -> ComposeTraversable f g a #
(Selective f, Applicative g, Traversable g) => Selective (ComposeTraversable f g) # |
Instance details Defined in Control.Selective Methods select :: ComposeTraversable f g (Either a b) -> ComposeTraversable f g (a -> b) -> ComposeTraversable f g b #