Community
Modules 26

Data.Functor.Contravariant.Decide

provisional

This module is only available if building with GHC 8.6 or later, or if the +contravariant cabal build flag is available.

class Contravariant f => Decide f

The contravariant analogue of Alt.

If one thinks of f a as a consumer of as, then decide allows one to handle the consumption of a value by choosing to handle it via exactly one of two independent consumers. It redirects the input completely into one of two consumers.

decide takes the "decision" method and the two potential consumers, and returns the wrapped/combined consumer.

Mathematically, a functor being an instance of Decide means that it is "semigroupoidal" with respect to the contravariant "either-based" Day convolution (data EitherDay f g a = forall b c. EitherDay (f b) (g c) (a -> Either b c)). That is, it is possible to define a function @(f `EitherDay` f) a -> f a@ in a way that is associative.

decide :: (a -> Either b c) -> f b -> f c -> f a

Takes the "decision" method and the two potential consumers, and returns the wrapped/combined consumer.

gdecide :: (Generic1 f, Decide (Rep1 f)) => (a -> Either b c) -> f b -> f c -> f a

Generic decide. Caveats:

  1. Will not compile if f is a sum type.

  2. Will not compile if f contains fields that do not mention its type variable.

  3. -XDeriveGeneric is not smart enough to make instances where the type variable appears in negative position.

decided :: Decide f => f b -> f c -> f (Either b c)

For decided x y, the resulting f (Either b c) will direct Lefts to be consumed by x, and Rights to be consumed by y.

gdecided :: (Generic1 f, Decide (Rep1 f)) => f b -> f c -> f (Either b c)

Generic decided. Caveats are the same as for gdecide.

Instances

26
  • instance Decidable f => Decide (WrappedDivisible f)

    This instance is only available if the +contravariant cabal flag is enabled.

  • instance Decide Comparison
  • instance Decide Equivalence
  • instance Decide Predicate
  • instance Decide (Op r)

    Unlike Decidable, requires no constraint on r.

  • instance Decide f => Decide (Alt f)
  • instance Decide U1
  • instance Decide V1

    Has no Decidable or Conclude instance.

  • instance Decide f => Decide (Rec1 f)
  • instance Decide f => Decide (M1 i c f)
  • instance (Decide f, Decide g) => Decide (f :*: g)
  • instance (Apply f, Decide g) => Decide (f :.: g)

    Unlike Decidable, requires only Apply on f.

  • instance Decide f => Decide (Backwards f)
  • instance Decide f => Decide (IdentityT f)
  • instance Decide m => Decide (ReaderT r m)
  • instance Decide m => Decide (Lazy.RWST r w s m)
  • instance Decide m => Decide (Strict.RWST r w s m)
  • instance Divise m => Decide (MaybeT m)
  • instance Decide m => Decide (Lazy.StateT s m)
  • instance Decide m => Decide (Strict.StateT s m)
  • instance Decide m => Decide (Lazy.WriterT w m)
  • instance Decide m => Decide (Strict.WriterT w m)
  • instance (Apply f, Decide g) => Decide (Compose f g)

    Unlike Decidable, requires only Apply on f.

  • instance (Decide f, Decide g) => Decide (Product f g)
  • instance Decide f => Decide (Reverse f)
  • instance Decide Proxy
Maintainer
Edward Kmett <ekmett@gmail.com>
Portability
portable
Copyright
(C) 2021 Edward Kmett
License
BSD-style (see the file LICENSE)
Build record and source files

Community contribution. The service has not verified this documentation.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 4ac4693dc44e2bb370a93502d1bf29784374032a00ad7b3d02803e3d433c0b16

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.