{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Operations on /sums/, combining effects into a /signature/.
--
-- @since 0.1.0.0
module Control.Effect.Sum
( -- * Membership
  Member(..)
, Members
  -- * Sums
, (:+:)(..)
, reassociateSumL
) where

import Data.Kind (Constraint, Type)

-- | Higher-order sums are used to combine multiple effects into a signature, typically by chaining on the right.
data (f :+: g) (m :: Type -> Type) k
  = L (f m k)
  | R (g m k)
  deriving ((:+:) f g m k -> (:+:) f g m k -> Bool
((:+:) f g m k -> (:+:) f g m k -> Bool)
-> ((:+:) f g m k -> (:+:) f g m k -> Bool) -> Eq ((:+:) f g m k)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Eq (f m k), Eq (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
$c== :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Eq (f m k), Eq (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
== :: (:+:) f g m k -> (:+:) f g m k -> Bool
$c/= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Eq (f m k), Eq (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
/= :: (:+:) f g m k -> (:+:) f g m k -> Bool
Eq, (forall m. Monoid m => (:+:) f g m m -> m)
-> (forall m a. Monoid m => (a -> m) -> (:+:) f g m a -> m)
-> (forall m a. Monoid m => (a -> m) -> (:+:) f g m a -> m)
-> (forall a b. (a -> b -> b) -> b -> (:+:) f g m a -> b)
-> (forall a b. (a -> b -> b) -> b -> (:+:) f g m a -> b)
-> (forall b a. (b -> a -> b) -> b -> (:+:) f g m a -> b)
-> (forall b a. (b -> a -> b) -> b -> (:+:) f g m a -> b)
-> (forall a. (a -> a -> a) -> (:+:) f g m a -> a)
-> (forall a. (a -> a -> a) -> (:+:) f g m a -> a)
-> (forall a. (:+:) f g m a -> [a])
-> (forall a. (:+:) f g m a -> Bool)
-> (forall a. (:+:) f g m a -> Int)
-> (forall a. Eq a => a -> (:+:) f g m a -> Bool)
-> (forall a. Ord a => (:+:) f g m a -> a)
-> (forall a. Ord a => (:+:) f g m a -> a)
-> (forall a. Num a => (:+:) f g m a -> a)
-> (forall a. Num a => (:+:) f g m a -> a)
-> Foldable ((:+:) f g m)
forall a. Eq a => a -> (:+:) f g m a -> Bool
forall a. Num a => (:+:) f g m a -> a
forall a. Ord a => (:+:) f g m a -> a
forall m. Monoid m => (:+:) f g m m -> m
forall a. (:+:) f g m a -> Bool
forall a. (:+:) f g m a -> Int
forall a. (:+:) f g m a -> [a]
forall a. (a -> a -> a) -> (:+:) f g m a -> a
forall m a. Monoid m => (a -> m) -> (:+:) f g m a -> m
forall b a. (b -> a -> b) -> b -> (:+:) f g m a -> b
forall a b. (a -> b -> b) -> b -> (:+:) f g m a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Eq a) =>
a -> (:+:) f g m a -> Bool
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Num a) =>
(:+:) f g m a -> a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Ord a) =>
(:+:) f g m a -> a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) m.
(Foldable (f m), Foldable (g m), Monoid m) =>
(:+:) f g m m -> m
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> Bool
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> Int
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> [a]
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(a -> a -> a) -> (:+:) f g m a -> a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) m a.
(Foldable (f m), Foldable (g m), Monoid m) =>
(a -> m) -> (:+:) f g m a -> m
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) b a.
(Foldable (f m), Foldable (g m)) =>
(b -> a -> b) -> b -> (:+:) f g m a -> b
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Foldable (f m), Foldable (g m)) =>
(a -> b -> b) -> b -> (:+:) f g m a -> b
$cfold :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) m.
(Foldable (f m), Foldable (g m), Monoid m) =>
(:+:) f g m m -> m
fold :: forall m. Monoid m => (:+:) f g m m -> m
$cfoldMap :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) m a.
(Foldable (f m), Foldable (g m), Monoid m) =>
(a -> m) -> (:+:) f g m a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> (:+:) f g m a -> m
$cfoldMap' :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) m a.
(Foldable (f m), Foldable (g m), Monoid m) =>
(a -> m) -> (:+:) f g m a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> (:+:) f g m a -> m
$cfoldr :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Foldable (f m), Foldable (g m)) =>
(a -> b -> b) -> b -> (:+:) f g m a -> b
foldr :: forall a b. (a -> b -> b) -> b -> (:+:) f g m a -> b
$cfoldr' :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Foldable (f m), Foldable (g m)) =>
(a -> b -> b) -> b -> (:+:) f g m a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> (:+:) f g m a -> b
$cfoldl :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) b a.
(Foldable (f m), Foldable (g m)) =>
(b -> a -> b) -> b -> (:+:) f g m a -> b
foldl :: forall b a. (b -> a -> b) -> b -> (:+:) f g m a -> b
$cfoldl' :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) b a.
(Foldable (f m), Foldable (g m)) =>
(b -> a -> b) -> b -> (:+:) f g m a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> (:+:) f g m a -> b
$cfoldr1 :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(a -> a -> a) -> (:+:) f g m a -> a
foldr1 :: forall a. (a -> a -> a) -> (:+:) f g m a -> a
$cfoldl1 :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(a -> a -> a) -> (:+:) f g m a -> a
foldl1 :: forall a. (a -> a -> a) -> (:+:) f g m a -> a
$ctoList :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> [a]
toList :: forall a. (:+:) f g m a -> [a]
$cnull :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> Bool
null :: forall a. (:+:) f g m a -> Bool
$clength :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m)) =>
(:+:) f g m a -> Int
length :: forall a. (:+:) f g m a -> Int
$celem :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Eq a) =>
a -> (:+:) f g m a -> Bool
elem :: forall a. Eq a => a -> (:+:) f g m a -> Bool
$cmaximum :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Ord a) =>
(:+:) f g m a -> a
maximum :: forall a. Ord a => (:+:) f g m a -> a
$cminimum :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Ord a) =>
(:+:) f g m a -> a
minimum :: forall a. Ord a => (:+:) f g m a -> a
$csum :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Num a) =>
(:+:) f g m a -> a
sum :: forall a. Num a => (:+:) f g m a -> a
$cproduct :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a.
(Foldable (f m), Foldable (g m), Num a) =>
(:+:) f g m a -> a
product :: forall a. Num a => (:+:) f g m a -> a
Foldable, (forall a b. (a -> b) -> (:+:) f g m a -> (:+:) f g m b)
-> (forall a b. a -> (:+:) f g m b -> (:+:) f g m a)
-> Functor ((:+:) f g m)
forall a b. a -> (:+:) f g m b -> (:+:) f g m a
forall a b. (a -> b) -> (:+:) f g m a -> (:+:) f g m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Functor (f m), Functor (g m)) =>
a -> (:+:) f g m b -> (:+:) f g m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Functor (f m), Functor (g m)) =>
(a -> b) -> (:+:) f g m a -> (:+:) f g m b
$cfmap :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Functor (f m), Functor (g m)) =>
(a -> b) -> (:+:) f g m a -> (:+:) f g m b
fmap :: forall a b. (a -> b) -> (:+:) f g m a -> (:+:) f g m b
$c<$ :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) a b.
(Functor (f m), Functor (g m)) =>
a -> (:+:) f g m b -> (:+:) f g m a
<$ :: forall a b. a -> (:+:) f g m b -> (:+:) f g m a
Functor, Eq ((:+:) f g m k)
Eq ((:+:) f g m k) =>
((:+:) f g m k -> (:+:) f g m k -> Ordering)
-> ((:+:) f g m k -> (:+:) f g m k -> Bool)
-> ((:+:) f g m k -> (:+:) f g m k -> Bool)
-> ((:+:) f g m k -> (:+:) f g m k -> Bool)
-> ((:+:) f g m k -> (:+:) f g m k -> Bool)
-> ((:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k)
-> ((:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k)
-> Ord ((:+:) f g m k)
(:+:) f g m k -> (:+:) f g m k -> Bool
(:+:) f g m k -> (:+:) f g m k -> Ordering
(:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
Eq ((:+:) f g m k)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Ordering
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
$ccompare :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Ordering
compare :: (:+:) f g m k -> (:+:) f g m k -> Ordering
$c< :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
< :: (:+:) f g m k -> (:+:) f g m k -> Bool
$c<= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
<= :: (:+:) f g m k -> (:+:) f g m k -> Bool
$c> :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
> :: (:+:) f g m k -> (:+:) f g m k -> Bool
$c>= :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> Bool
>= :: (:+:) f g m k -> (:+:) f g m k -> Bool
$cmax :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
max :: (:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
$cmin :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Ord (f m k), Ord (g m k)) =>
(:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
min :: (:+:) f g m k -> (:+:) f g m k -> (:+:) f g m k
Ord, Int -> (:+:) f g m k -> ShowS
[(:+:) f g m k] -> ShowS
(:+:) f g m k -> String
(Int -> (:+:) f g m k -> ShowS)
-> ((:+:) f g m k -> String)
-> ([(:+:) f g m k] -> ShowS)
-> Show ((:+:) f g m k)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
Int -> (:+:) f g m k -> ShowS
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
[(:+:) f g m k] -> ShowS
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
(:+:) f g m k -> String
$cshowsPrec :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
Int -> (:+:) f g m k -> ShowS
showsPrec :: Int -> (:+:) f g m k -> ShowS
$cshow :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
(:+:) f g m k -> String
show :: (:+:) f g m k -> String
$cshowList :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
(Show (f m k), Show (g m k)) =>
[(:+:) f g m k] -> ShowS
showList :: [(:+:) f g m k] -> ShowS
Show, Functor ((:+:) f g m)
Foldable ((:+:) f g m)
(Functor ((:+:) f g m), Foldable ((:+:) f g m)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> (:+:) f g m a -> f ((:+:) f g m b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    (:+:) f g m (f a) -> f ((:+:) f g m a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> (:+:) f g m a -> m ((:+:) f g m b))
-> (forall (m :: * -> *) a.
    Monad m =>
    (:+:) f g m (m a) -> m ((:+:) f g m a))
-> Traversable ((:+:) f g m)
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
(:+:) f g m (m a) -> m ((:+:) f g m a)
forall (f :: * -> *) a.
Applicative f =>
(:+:) f g m (f a) -> f ((:+:) f g m a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (:+:) f g m a -> m ((:+:) f g m b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (:+:) f g m a -> f ((:+:) f g m b)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *).
(Traversable (f m), Traversable (g m)) =>
Functor ((:+:) f g m)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *).
(Traversable (f m), Traversable (g m)) =>
Foldable ((:+:) f g m)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (m :: * -> *) a.
(Traversable (f m), Traversable (g m), Monad m) =>
(:+:) f g m (m a) -> m ((:+:) f g m a)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (f :: * -> *) a.
(Traversable (f m), Traversable (g m), Applicative f) =>
(:+:) f g m (f a) -> f ((:+:) f g m a)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (m :: * -> *) a b.
(Traversable (f m), Traversable (g m), Monad m) =>
(a -> m b) -> (:+:) f g m a -> m ((:+:) f g m b)
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (f :: * -> *) a b.
(Traversable (f m), Traversable (g m), Applicative f) =>
(a -> f b) -> (:+:) f g m a -> f ((:+:) f g m b)
$ctraverse :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (f :: * -> *) a b.
(Traversable (f m), Traversable (g m), Applicative f) =>
(a -> f b) -> (:+:) f g m a -> f ((:+:) f g m b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> (:+:) f g m a -> f ((:+:) f g m b)
$csequenceA :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (f :: * -> *) a.
(Traversable (f m), Traversable (g m), Applicative f) =>
(:+:) f g m (f a) -> f ((:+:) f g m a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
(:+:) f g m (f a) -> f ((:+:) f g m a)
$cmapM :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (m :: * -> *) a b.
(Traversable (f m), Traversable (g m), Monad m) =>
(a -> m b) -> (:+:) f g m a -> m ((:+:) f g m b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> (:+:) f g m a -> m ((:+:) f g m b)
$csequence :: forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) (m :: * -> *) a.
(Traversable (f m), Traversable (g m), Monad m) =>
(:+:) f g m (m a) -> m ((:+:) f g m a)
sequence :: forall (m :: * -> *) a.
Monad m =>
(:+:) f g m (m a) -> m ((:+:) f g m a)
Traversable)

infixr 4 :+:


-- | The class of types present in a signature.
--
--   This is based on Wouter Swierstra’s design described in [Data types à la carte](http://www.cs.ru.nl/~W.Swierstra/Publications/DataTypesALaCarte.pdf). As described therein, overlapping instances are required in order to distinguish e.g. left-occurrence from right-recursion.
--
--   It should not generally be necessary for you to define new 'Member' instances, but these are not specifically prohibited if you wish to get creative.
--
-- @since 0.1.0.0
class Member (sub :: (Type -> Type) -> (Type -> Type)) sup where
  -- | Inject a member of a signature into the signature.
  inj :: sub m a -> sup m a

-- | Reflexivity: @t@ is a member of itself.
instance Member t t where
  inj :: forall (m :: * -> *) a. t m a -> t m a
inj = t m a -> t m a
forall a. a -> a
id
  {-# INLINE inj #-}

-- | Left-recursion: if @t@ is a member of @l1 ':+:' l2 ':+:' r@, then we can inject it into @(l1 ':+:' l2) ':+:' r@ by injection into a right-recursive signature, followed by left-association.
instance {-# OVERLAPPABLE #-}
         Member t (l1 :+: l2 :+: r)
      => Member t ((l1 :+: l2) :+: r) where
  inj :: forall (m :: * -> *) a. t m a -> (:+:) (l1 :+: l2) r m a
inj = (:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a
forall (l1 :: (* -> *) -> * -> *) (l2 :: (* -> *) -> * -> *)
       (r :: (* -> *) -> * -> *) (m :: * -> *) a.
(:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a
reassociateSumL ((:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a)
-> (t m a -> (:+:) l1 (l2 :+: r) m a)
-> t m a
-> (:+:) (l1 :+: l2) r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. t m a -> (:+:) l1 (l2 :+: r) m a
forall (m :: * -> *) a. t m a -> (:+:) l1 (l2 :+: r) m a
forall (sub :: (* -> *) -> * -> *) (sup :: (* -> *) -> * -> *)
       (m :: * -> *) a.
Member sub sup =>
sub m a -> sup m a
inj
  {-# INLINE inj #-}

-- | Left-occurrence: if @t@ is at the head of a signature, we can inject it in O(1).
instance {-# OVERLAPPABLE #-}
         Member l (l :+: r) where
  inj :: forall (m :: * -> *) a. l m a -> (:+:) l r m a
inj = l m a -> (:+:) l r m a
forall (l :: (* -> *) -> * -> *) (r :: (* -> *) -> * -> *)
       (m :: * -> *) a.
l m a -> (:+:) l r m a
L
  {-# INLINE inj #-}

-- | Right-recursion: if @t@ is a member of @r@, we can inject it into @r@ in O(n), followed by lifting that into @l ':+:' r@ in O(1).
instance {-# OVERLAPPABLE #-}
         Member l r
      => Member l (l' :+: r) where
  inj :: forall (m :: * -> *) a. l m a -> (:+:) l' r m a
inj = r m a -> (:+:) l' r m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R (r m a -> (:+:) l' r m a)
-> (l m a -> r m a) -> l m a -> (:+:) l' r m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l m a -> r m a
forall (m :: * -> *) a. l m a -> r m a
forall (sub :: (* -> *) -> * -> *) (sup :: (* -> *) -> * -> *)
       (m :: * -> *) a.
Member sub sup =>
sub m a -> sup m a
inj
  {-# INLINE inj #-}


-- | Reassociate a right-nested sum leftwards.
--
-- @since 1.0.2.0
reassociateSumL :: (l1 :+: l2 :+: r) m a -> ((l1 :+: l2) :+: r) m a
reassociateSumL :: forall (l1 :: (* -> *) -> * -> *) (l2 :: (* -> *) -> * -> *)
       (r :: (* -> *) -> * -> *) (m :: * -> *) a.
(:+:) l1 (l2 :+: r) m a -> (:+:) (l1 :+: l2) r m a
reassociateSumL = \case
  L l1 m a
l     -> (:+:) l1 l2 m a -> (:+:) (l1 :+: l2) r m a
forall (l :: (* -> *) -> * -> *) (r :: (* -> *) -> * -> *)
       (m :: * -> *) a.
l m a -> (:+:) l r m a
L (l1 m a -> (:+:) l1 l2 m a
forall (l :: (* -> *) -> * -> *) (r :: (* -> *) -> * -> *)
       (m :: * -> *) a.
l m a -> (:+:) l r m a
L l1 m a
l)
  R (L l2 m a
l) -> (:+:) l1 l2 m a -> (:+:) (l1 :+: l2) r m a
forall (l :: (* -> *) -> * -> *) (r :: (* -> *) -> * -> *)
       (m :: * -> *) a.
l m a -> (:+:) l r m a
L (l2 m a -> (:+:) l1 l2 m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R l2 m a
l)
  R (R r m a
r) -> r m a -> (:+:) (l1 :+: l2) r m a
forall (f :: (* -> *) -> * -> *) (g :: (* -> *) -> * -> *)
       (m :: * -> *) k.
g m k -> (:+:) f g m k
R r m a
r
{-# INLINE reassociateSumL #-}


-- | Decompose sums on the left into multiple 'Member' constraints.
--
-- Note that while this, and by extension 'Control.Algebra.Has', can be used to group together multiple membership checks into a single (composite) constraint, large signatures on the left can slow compiles down due to [a problem with recursive type families](https://gitlab.haskell.org/ghc/ghc/issues/8095).
--
-- @since 1.0.0.0
type family Members sub sup :: Constraint where
  Members (l :+: r) u = (Members l u, Members r u)
  Members t         u = Member t u