{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Data.Functor.ProductIsomorphic.Class (
ProductIsoFunctor (..),
ProductIsoApplicative (..),
ProductIsoAlternative (..),
ProductIsoEmpty (..),
peRightR, peLeftR,
) where
import Data.Functor.ProductIsomorphic.Unsafe (ProductConstructor)
import Data.Functor.ProductIsomorphic.TupleInstances ()
class ProductIsoFunctor f where
(|$|) :: ProductConstructor (a -> b) => (a -> b) -> f a -> f b
class ProductIsoFunctor f => ProductIsoApplicative f where
pureP :: ProductConstructor a => a -> f a
(|*|) :: f (a -> b) -> f a -> f b
class ProductIsoApplicative f => ProductIsoAlternative f where
emptyP :: f a
(|||) :: f a -> f a -> f a
infixl 4 |$|, |*|
infixl 3 |||
class ProductIsoApplicative f => ProductIsoEmpty f e where
pureE :: f e
peRight :: f (a, e) -> f a
peLeft :: f (e, a) -> f a
peRightR :: ProductIsoEmpty f e
=> f a
-> f (a, e)
peRightR :: forall (f :: * -> *) e a. ProductIsoEmpty f e => f a -> f (a, e)
peRightR f a
p = (,) forall (f :: * -> *) a b.
(ProductIsoFunctor f, ProductConstructor (a -> b)) =>
(a -> b) -> f a -> f b
|$| f a
p forall (f :: * -> *) a b.
ProductIsoApplicative f =>
f (a -> b) -> f a -> f b
|*| forall (f :: * -> *) e. ProductIsoEmpty f e => f e
pureE
{-# INLINABLE peRightR #-}
peLeftR :: ProductIsoEmpty f e
=> f a
-> f (e, a)
peLeftR :: forall (f :: * -> *) e a. ProductIsoEmpty f e => f a -> f (e, a)
peLeftR f a
p = (,) forall (f :: * -> *) a b.
(ProductIsoFunctor f, ProductConstructor (a -> b)) =>
(a -> b) -> f a -> f b
|$| forall (f :: * -> *) e. ProductIsoEmpty f e => f e
pureE forall (f :: * -> *) a b.
ProductIsoApplicative f =>
f (a -> b) -> f a -> f b
|*| f a
p
{-# INLINABLE peLeftR #-}