{-# 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 = second inl ||| second 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 (a, Left b) = Left (a,b)
distribute (a, Right c) = Right (a,c)