module Data.Bifunctor.Assoc (
Assoc (..),
) where
import Control.Applicative (Const (..))
import Data.Bifunctor (Bifunctor (..))
import Data.Bifunctor.Flip (Flip (..))
import Data.Bifunctor.Product (Product (..))
import Data.Bifunctor.Tannen (Tannen (..))
import Data.Tagged (Tagged (..))
class Bifunctor p => Assoc p where
assoc :: p (p a b) c -> p a (p b c)
unassoc :: p a (p b c) -> p (p a b) c
instance Assoc (,) where
assoc :: forall a b c. ((a, b), c) -> (a, (b, c))
assoc ((a
a, b
b), c
c) = (a
a, (b
b, c
c))
unassoc :: forall a b c. (a, (b, c)) -> ((a, b), c)
unassoc (a
a, (b
b, c
c)) = ((a
a, b
b), c
c)
instance Assoc Either where
assoc :: forall a b c. Either (Either a b) c -> Either a (Either b c)
assoc (Left (Left a
a)) = forall a b. a -> Either a b
Left a
a
assoc (Left (Right b
b)) = forall a b. b -> Either a b
Right (forall a b. a -> Either a b
Left b
b)
assoc (Right c
c) = forall a b. b -> Either a b
Right (forall a b. b -> Either a b
Right c
c)
unassoc :: forall a b c. Either a (Either b c) -> Either (Either a b) c
unassoc (Left a
a) = forall a b. a -> Either a b
Left (forall a b. a -> Either a b
Left a
a)
unassoc (Right (Left b
b)) = forall a b. a -> Either a b
Left (forall a b. b -> Either a b
Right b
b)
unassoc (Right (Right c
c)) = forall a b. b -> Either a b
Right c
c
instance Assoc Const where
assoc :: forall a b c. Const (Const a b) c -> Const a (Const b c)
assoc (Const (Const a
a)) = forall {k} a (b :: k). a -> Const a b
Const a
a
unassoc :: forall a b c. Const a (Const b c) -> Const (Const a b) c
unassoc (Const a
a) = forall {k} a (b :: k). a -> Const a b
Const (forall {k} a (b :: k). a -> Const a b
Const a
a)
instance Assoc Tagged where
assoc :: forall a b c. Tagged (Tagged a b) c -> Tagged a (Tagged b c)
assoc (Tagged c
a) = forall {k} (s :: k) b. b -> Tagged s b
Tagged (forall {k} (s :: k) b. b -> Tagged s b
Tagged c
a)
unassoc :: forall a b c. Tagged a (Tagged b c) -> Tagged (Tagged a b) c
unassoc (Tagged (Tagged c
a)) = forall {k} (s :: k) b. b -> Tagged s b
Tagged c
a
instance Assoc p => Assoc (Flip p) where
assoc :: forall a b c. Flip p (Flip p a b) c -> Flip p a (Flip p b c)
assoc = forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Assoc p =>
p a (p b c) -> p (p a b) c
unassoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip
unassoc :: forall a b c. Flip p a (Flip p b c) -> Flip p (Flip p a b) c
unassoc = forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second forall {k} {k1} (p :: k -> k1 -> *) (a :: k1) (b :: k).
p b a -> Flip p a b
Flip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Assoc p =>
p (p a b) c -> p a (p b c)
assoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k1} {k2} (p :: k1 -> k2 -> *) (a :: k2) (b :: k1).
Flip p a b -> p b a
runFlip