semigroupoids-6.0.1: Semigroupoids: Category sans id

Copyright | (C) 2021 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | provisional
Portability | portable
Safe Haskell | Safe
Language | Haskell2010

Data.Functor.Contravariant.Divise

Description

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

Synopsis

- class Contravariant f => Divise (f :: Type -> Type) where
  - divise :: (a -> (b, c)) -> f b -> f c -> f a
- gdivise :: (Divise (Rep1 f), Generic1 f) => (a -> (b, c)) -> f b -> f c -> f a
- divised :: Divise f => f a -> f b -> f (a, b)
- gdivised :: (Generic1 f, Divise (Rep1 f)) => f a -> f b -> f (a, b)
- newtype WrappedDivisible (f :: Type -> Type) a = WrapDivisible {
  - unwrapDivisible :: f a
  }

# Documentation

class Contravariant f => Divise (f :: Type -> Type) where #

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

If one thinks of `f a` as a consumer of `a`s, 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.

Since: 5.3.6

Methods

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.

#### Instances

Instances details

Divise Comparison # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Comparison b -> Comparison c -> Comparison a #
Divise Equivalence # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Equivalence b -> Equivalence c -> Equivalence a #
Divise Predicate # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Predicate b -> Predicate c -> Predicate a #
Semigroup r => Divise (Op r) # | Unlike `Divisible`, requires only `Semigroup` on `r`. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Op r b -> Op r c -> Op r a #
Divise (Proxy :: Type -> Type) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Proxy b -> Proxy c -> Proxy a #
Divise (U1 :: Type -> Type) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> U1 b -> U1 c -> U1 a #
Divise (V1 :: Type -> Type) # | Has no `Divisible` instance. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> V1 b -> V1 c -> V1 a #
Divisible f => Divise (WrappedDivisible f) # | This instance is only available if the `+contravariant` `cabal` flag is enabled. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> WrappedDivisible f b -> WrappedDivisible f c -> WrappedDivisible f a #
Divise m => Divise (MaybeT m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> MaybeT m b -> MaybeT m c -> MaybeT m a #
Semigroup m => Divise (Const m :: Type -> Type) # | Unlike `Divisible`, requires only `Semigroup` on `m`. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Const m b -> Const m c -> Const m a #
Divise f => Divise (Alt f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Alt f b -> Alt f c -> Alt f a #
Divise f => Divise (Rec1 f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Rec1 f b -> Rec1 f c -> Rec1 f a #
Divise f => Divise (Backwards f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Backwards f b -> Backwards f c -> Backwards f a #
Divise m => Divise (ExceptT e m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> ExceptT e m b -> ExceptT e m c -> ExceptT e m a #
Divise f => Divise (IdentityT f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> IdentityT f b -> IdentityT f c -> IdentityT f a #
Divise m => Divise (ReaderT r m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> ReaderT r m b -> ReaderT r m c -> ReaderT r m a #
Divise m => Divise (StateT s m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> StateT s m b -> StateT s m c -> StateT s m a #
Divise m => Divise (StateT s m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> StateT s m b -> StateT s m c -> StateT s m a #
Divise m => Divise (WriterT w m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> WriterT w m b -> WriterT w m c -> WriterT w m a #
Divise m => Divise (WriterT w m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> WriterT w m b -> WriterT w m c -> WriterT w m a #
Semigroup m => Divise (Constant m :: Type -> Type) # | Unlike `Divisible`, requires only `Semigroup` on `m`. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Constant m b -> Constant m c -> Constant m a #
Divise f => Divise (Reverse f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Reverse f b -> Reverse f c -> Reverse f a #
(Divise f, Divise g) => Divise (Product f g) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Product f g b -> Product f g c -> Product f g a #
(Divise f, Divise g) => Divise (f :*: g) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> (f :*: g) b -> (f :*: g) c -> (f :*: g) a #
(Apply f, Divise g) => Divise (Compose f g) # | Unlike `Divisible`, requires only `Apply` on `f`. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> Compose f g b -> Compose f g c -> Compose f g a #
(Apply f, Divise g) => Divise (f :.: g) # | Unlike `Divisible`, requires only `Apply` on `f`. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> (f :.: g) b -> (f :.: g) c -> (f :.: g) a #
Divise f => Divise (M1 i c f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c0)) -> M1 i c f b -> M1 i c f c0 -> M1 i c f a #
Divise m => Divise (RWST r w s m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> RWST r w s m b -> RWST r w s m c -> RWST r w s m a #
Divise m => Divise (RWST r w s m) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> RWST r w s m b -> RWST r w s m c -> RWST r w s m a #

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.

Since: 5.3.8

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

Since: 5.3.6

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

Generic `divised`. Caveats are the same as for `gdivise`.

Since: 5.3.8

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

Wrap a `Divisible` to be used as a member of `Divise`

Since: 5.3.6

Constructors

WrapDivisible |
Fields unwrapDivisible :: f a

#### Instances

Instances details

Contravariant f => Contravariant (WrappedDivisible f) # | Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods contramap :: (a' -> a) -> WrappedDivisible f a -> WrappedDivisible f a' # (>$) :: b -> WrappedDivisible f b -> WrappedDivisible f a #
Decidable f => Conclude (WrappedDivisible f) # | This instance is only available if the `+contravariant` `cabal` flag is enabled. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Conclude Methods conclude :: (a -> Void) -> WrappedDivisible f a #
Decidable f => Decide (WrappedDivisible f) # | This instance is only available if the `+contravariant` `cabal` flag is enabled. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Decide Methods decide :: (a -> Either b c) -> WrappedDivisible f b -> WrappedDivisible f c -> WrappedDivisible f a #
Divisible f => Divise (WrappedDivisible f) # | This instance is only available if the `+contravariant` `cabal` flag is enabled. Since: 5.3.6
Instance details Defined in Data.Functor.Contravariant.Divise Methods divise :: (a -> (b, c)) -> WrappedDivisible f b -> WrappedDivisible f c -> WrappedDivisible f a #