{-# LANGUAGE CPP #-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
{-# LANGUAGE MultiParamTypeClasses #-}
module Control.Category.Associative
( Associative(..)
) where
import Control.Categorical.Bifunctor
class Bifunctor p k k k => Associative k p where
associate :: k (p (p a b) c) (p a (p b c))
disassociate :: k (p a (p b c)) (p (p a b) c)
instance Associative (->) (,) where
associate :: ((a, b), c) -> (a, (b, c))
associate ((a :: a
a,b :: b
b),c :: c
c) = (a
a,(b
b,c
c))
disassociate :: (a, (b, c)) -> ((a, b), c)
disassociate (a :: a
a,(b :: b
b,c :: c
c)) = ((a
a,b
b),c
c)
instance Associative (->) Either where
associate :: Either (Either a b) c -> Either a (Either b c)
associate (Left (Left a :: a
a)) = a -> Either a (Either b c)
forall a b. a -> Either a b
Left a
a
associate (Left (Right b :: b
b)) = Either b c -> Either a (Either b c)
forall a b. b -> Either a b
Right (b -> Either b c
forall a b. a -> Either a b
Left b
b)
associate (Right c :: c
c) = Either b c -> Either a (Either b c)
forall a b. b -> Either a b
Right (c -> Either b c
forall a b. b -> Either a b
Right c
c)
disassociate :: Either a (Either b c) -> Either (Either a b) c
disassociate (Left a :: a
a) = Either a b -> Either (Either a b) c
forall a b. a -> Either a b
Left (a -> Either a b
forall a b. a -> Either a b
Left a
a)
disassociate (Right (Left b :: b
b)) = Either a b -> Either (Either a b) c
forall a b. a -> Either a b
Left (b -> Either a b
forall a b. b -> Either a b
Right b
b)
disassociate (Right (Right c :: c
c)) = c -> Either (Either a b) c
forall a b. b -> Either a b
Right c
c