| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Profunctor.Cocartesian.Free
Synopsis
- data FreeCocartesian (p :: Type -> Type -> Type) a b
- liftF :: p a b -> FreeCocartesian p a b
- foldFree :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cocartesian q => (p :-> q) -> FreeCocartesian p :-> q
- emptyF :: forall (p :: Type -> Type -> Type) b. FreeCocartesian p Void b
- sumF :: forall (p :: Type -> Type -> Type) a b a' b'. FreeCocartesian p a b -> FreeCocartesian p a' b' -> FreeCocartesian p (Either a a') (Either b b')
- multF :: forall (p :: Type -> Type -> Type) (q :: Type -> Type -> Type) (r :: Type -> Type -> Type) a b a' b'. ProductOp p q r -> FreeCocartesian p a b -> FreeCocartesian q a' b' -> FreeCocartesian r (a, a') (b, b')
- newtype ForgetCocartesian (p :: Type -> Type -> Type) a b = ForgetCocartesian {
- recallCocartesian :: p a b
- assocEither :: Either (Either a b) c -> Either a (Either b c)
- unassocEither :: Either a (Either b c) -> Either (Either a b) c
- distL :: (a, Either b1 b2) -> Either (a, b1) (a, b2)
- undistL :: Either (a, b1) (a, b2) -> (a, Either b1 b2)
- distR :: (Either a1 a2, b) -> Either (a1, b) (a2, b)
- undistR :: Either (a1, b) (a2, b) -> (Either a1 a2, b)
The free Cocartesian profunctors
data FreeCocartesian (p :: Type -> Type -> Type) a b 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
Instances
liftF :: p a b -> FreeCocartesian p a b Source #
foldFree :: forall (q :: Type -> Type -> Type) (p :: Type -> Type -> Type). Cocartesian q => (p :-> q) -> FreeCocartesian p :-> q Source #
sumF :: forall (p :: Type -> Type -> Type) a b a' b'. FreeCocartesian p a b -> FreeCocartesian p a' b' -> FreeCocartesian p (Either a a') (Either b b') Source #
Distributive Cartesian on FreeCocartesian p
multF :: forall (p :: Type -> Type -> Type) (q :: Type -> Type -> Type) (r :: Type -> Type -> Type) a b a' b'. ProductOp p q r -> FreeCocartesian p a b -> FreeCocartesian q a' b' -> FreeCocartesian r (a, a') (b, b') Source #
Newtype wrapper
newtype ForgetCocartesian (p :: Type -> Type -> Type) a b Source #
Forgets Cocartesian instance from a Profunctor.
Constructors
| ForgetCocartesian | |
Fields
| |