{-# 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 p = (,) |$| p |*| pureE
{-# INLINABLE peRightR #-}
peLeftR :: ProductIsoEmpty f e
=> f a
-> f (e, a)
peLeftR p = (,) |$| pureE |*| p
{-# INLINABLE peLeftR #-}