Community
Modules 26

Data.Functor.Contravariant.Divise

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 => Divise f

The contravariant analogue of Apply; it is Divisible without conquer.

If one thinks of f a as a consumer of as, then divise allows one to handle the consumption of a value by splitting it between two consumers that consume separate parts of a.

divise takes the "splitting" method and the two sub-consumers, and returns the wrapped/combined consumer.

All instances of Divisible should be instances of Divise with divise = divide.

If a function is polymorphic over Divise f (as opposed to @Divisible f@), we can provide a stronger guarantee: namely, that any input consumed will be passed to at least one sub-consumer. With Divisible f, said input could potentially disappear into the void, as this is possible with conquer.

Mathematically, a functor being an instance of Divise means that it is "semigroupoidal" with respect to the contravariant (tupling) Day convolution. That is, it is possible to define a function @(f `Day` f) a -> f a@ in a way that is associative.

divise :: (a -> (b, c)) -> f b -> f c -> f a

Takes a "splitting" method and the two sub-consumers, and returns the wrapped/combined consumer.

gdivise :: (Divise (Rep1 f), Generic1 f) => (a -> (b, c)) -> f b -> f c -> f a

Generic divise. 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.

divised :: Divise f => f a -> f b -> f (a, b)

Combine a consumer of a with a consumer of b to get a consumer of (a, b).

'divised' = 'divise' 'id'

gdivised :: (Generic1 f, Divise (Rep1 f)) => f a -> f b -> f (a, b)

Generic divised. Caveats are the same as for gdivise.

Instances

30
  • instance Contravariant f => Contravariant (WrappedDivisible f)
  • instance Divisible f => Divise (WrappedDivisible f)

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

  • instance Semigroup r => Divise (Op r)

    Unlike Divisible, requires only Semigroup on r.

  • instance Semigroup m => Divise (Const m)

    Unlike Divisible, requires only Semigroup on m.

  • instance Semigroup m => Divise (Constant m)

    Unlike Divisible, requires only Semigroup on m.

  • instance Divise Comparison
  • instance Divise Equivalence
  • instance Divise Predicate
  • instance Divise Proxy
  • instance Divise f => Divise (Alt f)
  • instance Divise U1
  • instance Divise V1

    Has no Divisible instance.

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

    Unlike Divisible, requires only Apply on f.

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

    Unlike Divisible, requires only Apply on f.

  • instance (Divise f, Divise g) => Divise (Product f g)
  • instance Divise f => Divise (Reverse f)
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.