Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Profunctor.Cartesian.Free
Synopsis
- data FreeMonoidal (t :: Type -> Type -> Type) i (p :: Type -> Type -> Type) a b
- = Neutral (a -> i) (i -> b)
- | Cons (Day t p (FreeMonoidal t i p) a b)
- type FreeCartesian = FreeMonoidal (,) ()
- liftFreeCartesian :: p a b -> FreeCartesian p a b
- foldFreeCartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cartesian q => (p :-> q) -> FreeCartesian p :-> q
- type FreeCocartesian = FreeMonoidal Either Void
- liftFreeCocartesian :: p a b -> FreeCocartesian p a b
- foldFreeCocartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cocartesian q => (p :-> q) -> FreeCocartesian p :-> q
- newtype ForgetCartesian (p :: Type -> Type -> Type) a b = ForgetCartesian {
- recallCartesian :: p a b
- newtype ForgetCocartesian (p :: Type -> Type -> Type) a b = ForgetCocartesian {
- recallCocartesian :: p a b
Documentation
data FreeMonoidal (t :: Type -> Type -> Type) i (p :: Type -> Type -> Type) a b Source #
Constructs free monoidal profunctor with specified monoid. Each parameters of FreeMonoidal t i p
stands for:
t
for the monoidal producti
for the unit of the monoidal productt
p
for the profunctor generatingFreeMonoidal
For example, FreeMonoidal (,) () p
is the free Cartesian
profunctor.
Constructors
Neutral (a -> i) (i -> b) | |
Cons (Day t p (FreeMonoidal t i p) a b) |
Instances
type FreeCartesian = FreeMonoidal (,) () Source #
Free Cartesian profunctor is FreeMonoidal
profunctor with respect to
(,)
.
liftFreeCartesian :: p a b -> FreeCartesian p a b Source #
foldFreeCartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cartesian q => (p :-> q) -> FreeCartesian p :-> q Source #
type FreeCocartesian = FreeMonoidal Either Void Source #
Free Cocartesian profunctor is FreeMonoidal
profunctor with respect to
Either
.
Caution about Cartesian
instance
Note that
have an instance of FreeCocartesian
pCartesian
, by distributing
product on sums to sum of products of individual profunctors.
When it is desirable to disable Cartesian
instance of FreeCocartesian p
,
use ForgetCartesian
to ignore Cartesian
instance of p
.
Because there are some profunctors which are both Cartesian
and Cocartesian
but do not satisfy distributive laws,
using FreeCocartesian
with such profunctors might cause a surprising behavior.
For example,
is not distributive,
as Joker
[]Alternative []
is not distributive as shown below.
>>>
import Control.Applicative
>>>
let x = [id, id]
>>>
let y = [1]; z = [2]
>>>
x <*> (y <|> z)
[1,2,1,2]>>>
(x <*> y) <|> (x <*> z)
[1,1,2,2]
With such non-distributive Cartesian p
, foldFreeCocartesian
does not preserve
the Cartesian
operations. The following equation does not have to hold.
-- Not necessarily holds! foldFreeCocartesian id (ps *** qs) == foldFreeCocartesian id ps *** foldFreeCocartesian id qs
liftFreeCocartesian :: p a b -> FreeCocartesian p a b Source #
foldFreeCocartesian :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cocartesian q => (p :-> q) -> FreeCocartesian p :-> q Source #
newtype ForgetCartesian (p :: Type -> Type -> Type) a b Source #
Forgets Cartesian
instance from a Profunctor
.
Constructors
ForgetCartesian | |
Fields
|
Instances
newtype ForgetCocartesian (p :: Type -> Type -> Type) a b Source #
Forgets Cocartesian
instance from a Profunctor
.
Constructors
ForgetCocartesian | |
Fields
|