{-# LANGUAGE CPP #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
{-# LANGUAGE TypeOperators #-}
module Control.Category.Distributive
(
factor
, Distributive(..)
) where
import Prelude hiding (Functor, map, (.), id, fst, snd, curry, uncurry)
import Control.Categorical.Bifunctor
import Control.Category.Cartesian
factor :: (Cartesian k, CoCartesian k) => Sum k (Product k a b) (Product k a c) `k` Product k a (Sum k b c)
factor :: k (Sum k (Product k a b) (Product k a c)) (Product k a (Sum k b c))
factor = k b (Sum k b c) -> k (Product k a b) (Product k a (Sum k b c))
forall (q :: * -> * -> *) (s :: * -> * -> *) (t :: * -> * -> *) a b
c.
QFunctor q s t =>
s a b -> t (q c a) (q c b)
second k b (Sum k b c)
forall (k :: * -> * -> *) a b. CoCartesian k => k a (Sum k a b)
inl k (Product k a b) (Product k a (Sum k b c))
-> k (Product k a c) (Product k a (Sum k b c))
-> k (Sum k (Product k a b) (Product k a c))
(Product k a (Sum k b c))
forall (k :: * -> * -> *) a c b.
CoCartesian k =>
k a c -> k b c -> k (Sum k a b) c
||| k c (Sum k b c) -> k (Product k a c) (Product k a (Sum k b c))
forall (q :: * -> * -> *) (s :: * -> * -> *) (t :: * -> * -> *) a b
c.
QFunctor q s t =>
s a b -> t (q c a) (q c b)
second k c (Sum k b c)
forall (k :: * -> * -> *) b a. CoCartesian k => k b (Sum k a b)
inr
class (Cartesian k, CoCartesian k) => Distributive k where
distribute :: Product k a (Sum k b c) `k` Sum k (Product k a b) (Product k a c)
instance Distributive (->) where
distribute :: Product (->) a (Sum (->) b c)
-> Sum (->) (Product (->) a b) (Product (->) a c)
distribute (a, Left b) = (a, b) -> Either (a, b) (a, c)
forall a b. a -> Either a b
Left (a
a,b
b)
distribute (a, Right c) = (a, c) -> Either (a, b) (a, c)
forall a b. b -> Either a b
Right (a
a,c
c)