Copyright | (C) 2014-2015 Edward Kmett |
---|---|
License | BSD-style (see the file LICENSE) |
Maintainer | Edward Kmett <ekmett@gmail.com> |
Stability | provisional |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
This module supplies contravariant analogues to the Applicative
and Alternative
classes.
Contravariant Applicative
class Contravariant f => Divisible f where Source
A Divisible
contravariant functor is the contravariant analogue of Applicative
.
In denser jargon, a Divisible
contravariant functor is a monoid object in the category
of presheaves from Hask to Hask, equipped with Day convolution mapping the Cartesian
product of the source to the Cartesian product of the target.
By way of contrast, an Applicative
functor can be viewed as a monoid object in the
category of copresheaves from Hask to Hask, equipped with Day convolution mapping the
Cartesian product of the source to the Cartesian product of the target.
Given the canonical diagonal morphism:
delta a = (a,a)
should be associative with divide
delta
conquer
as a unit
divide
delta
mconquer
= mdivide
delta
conquer
m = mdivide
delta
(divide
delta
m n) o =divide
delta
m (divide
delta
n o)
With more general arguments you'll need to reassociate and project using the monoidal structure of the source category. (Here fst and snd are used in lieu of the more restricted lambda and rho, but this construction works with just a monoidal category.)
divide
f mconquer
=contramap
(fst
. f) mdivide
fconquer
m =contramap
(snd
. f) mdivide
f (divide
g m n) o =divide
f' m (divide
id
n o) where f' a = case f a of (bc,d) -> case g bc of (b,c) -> (a,(b,c))
Divisible Equivalence | |
Divisible Comparison | |
Divisible Predicate | |
Monoid r => Divisible (Op r) | |
(Divisible f, Applicative g) => Divisible (ComposeCF f g) | |
(Applicative f, Divisible g) => Divisible (ComposeFC f g) |
Contravariant Alternative
class Divisible f => Decidable f where Source
A Divisible
contravariant functor is a monoid object in the category of presheaves
from Hask to Hask, equipped with Day convolution mapping the cartesian product of the
source to the Cartesian product of the target.
choose
Left m (lose
f) = mchoose
Right (lose
f) m = mchoose
f (choose
g m n) o =divide
f' m (divide
id
n o) where f' bcd =either
(either
id
(Right
.Left
) . g) (Right
.Right
) . f
In addition, we expect the same kind of distributive law as is satisfied by the usual
covariant Alternative
, w.r.t Applicative
, which should be fully formulated and
added here at some point!
Decidable Equivalence | |
Decidable Comparison | |
Decidable Predicate | |
Monoid r => Decidable (Op r) | |
(Applicative f, Decidable g) => Decidable (ComposeFC f g) |