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 |
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 Source #
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
(as opposed to Divise
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
Divisible
fconquer
.
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
in a way that is associative.Day
f)
a -> f a
Since: 5.3.6
divise :: (a -> (b, c)) -> f b -> f c -> f a Source #
Takes a "splitting" method and the two sub-consumers, and returns the wrapped/combined consumer.
Instances
Divise Comparison Source # | Since: 5.3.6 |
Defined in Data.Functor.Contravariant.Divise divise :: (a -> (b, c)) -> Comparison b -> Comparison c -> Comparison a Source # | |
Divise Equivalence Source # | Since: 5.3.6 |
Defined in Data.Functor.Contravariant.Divise divise :: (a -> (b, c)) -> Equivalence b -> Equivalence c -> Equivalence a Source # | |
Divise Predicate Source # | Since: 5.3.6 |
Semigroup r => Divise (Op r) Source # | Unlike Since: 5.3.6 |
Divise (Proxy :: Type -> Type) Source # | Since: 5.3.6 |
Divise (U1 :: Type -> Type) Source # | Since: 5.3.6 |
Divise (V1 :: Type -> Type) Source # | Has no Since: 5.3.6 |
Divisible f => Divise (WrappedDivisible f) Source # | This instance is only available if the Since: 5.3.6 |
Defined in Data.Functor.Contravariant.Divise divise :: (a -> (b, c)) -> WrappedDivisible f b -> WrappedDivisible f c -> WrappedDivisible f a Source # | |
Divise m => Divise (MaybeT m) Source # | Since: 5.3.6 |
Semigroup m => Divise (Const m :: Type -> Type) Source # | Unlike Since: 5.3.6 |
Divise f => Divise (Alt f) Source # | Since: 5.3.6 |
Divise f => Divise (Rec1 f) Source # | Since: 5.3.6 |
Divise f => Divise (Backwards f) Source # | Since: 5.3.6 |
Divise m => Divise (ExceptT e m) Source # | Since: 5.3.6 |
Divise f => Divise (IdentityT f) Source # | Since: 5.3.6 |
Divise m => Divise (ReaderT r m) Source # | Since: 5.3.6 |
Divise m => Divise (StateT s m) Source # | Since: 5.3.6 |
Divise m => Divise (StateT s m) Source # | Since: 5.3.6 |
Divise m => Divise (WriterT w m) Source # | Since: 5.3.6 |
Divise m => Divise (WriterT w m) Source # | Since: 5.3.6 |
Semigroup m => Divise (Constant m :: Type -> Type) Source # | Unlike Since: 5.3.6 |
Divise f => Divise (Reverse f) Source # | Since: 5.3.6 |
(Divise f, Divise g) => Divise (Product f g) Source # | Since: 5.3.6 |
(Divise f, Divise g) => Divise (f :*: g) Source # | Since: 5.3.6 |
(Apply f, Divise g) => Divise (Compose f g) Source # | Unlike Since: 5.3.6 |
(Apply f, Divise g) => Divise (f :.: g) Source # | Unlike Since: 5.3.6 |
Divise f => Divise (M1 i c f) Source # | Since: 5.3.6 |
Divise m => Divise (RWST r w s m) Source # | Since: 5.3.6 |
Divise m => Divise (RWST r w s m) Source # | Since: 5.3.6 |
gdivise :: (Divise (Rep1 f), Generic1 f) => (a -> (b, c)) -> f b -> f c -> f a Source #
Generic divise
. Caveats:
- Will not compile if
f
is a sum type. - Will not compile if
f
contains fields that do not mention its type variable. -XDeriveGeneric
is not smart enough to make instances where the type variable appears in negative position.
Since: 5.3.8
newtype WrappedDivisible (f :: Type -> Type) a Source #
WrapDivisible | |
|