module Parameterized.Control.Applicative
( PUnary
, PPointed(..)
, PApplicative(..)
, (&<*>)
, (&*>)
, (&<*)
, pliftA
, pliftA2
, pliftA3
, PEmpty(..)
, PAlternative(..)
, (&<|>)
) where
import Data.Kind
type family PUnary (m :: k -> Type -> Type) (t :: k) = (r :: Type -> Type) | r -> m t
class PPointed (m :: k -> Type -> Type) (id :: k) where
ppure :: a -> PUnary m id a
class (Functor (PUnary m t), Functor (PUnary m u), Functor (PUnary m v)) =>
PApplicative (m :: k -> Type -> Type) (t :: k) (u :: k) (v :: k) | t u -> v where
papply :: PUnary m t (a -> b) -> PUnary m u a -> PUnary m v b
(&<*>) :: (PApplicative m t u v) => PUnary m t (a -> b) -> PUnary m u a -> PUnary m v b
(&<*>) = papply
infixl 4 &<*>
infixl 4 `papply`
(&*>) :: (PApplicative m t u v) => PUnary m t a -> PUnary m u b -> PUnary m v b
a1 &*> a2 = (id <$ a1) &<*> a2
infixl 4 &*>
(&<*) :: (PApplicative m t u v) => PUnary m t a -> PUnary m u b -> PUnary m v a
(&<*) = pliftA2 const
infixl 4 &<*
pliftA :: (Functor (PUnary m t)) => (a -> b) -> PUnary m t a -> PUnary m t b
pliftA f x = f <$> x
pliftA2 :: (PApplicative m t u v) => (a -> b -> c) -> PUnary m t a -> PUnary m u b -> PUnary m v c
pliftA2 f x y = (f <$> x) `papply` y
pliftA3
:: ( PApplicative m t u v
, PApplicative m v w x
)
=> (a -> b -> c -> d) -> PUnary m t a -> PUnary m u b -> PUnary m w c -> PUnary m x d
pliftA3 f a b c = pliftA2 f a b &<*> c
class PEmpty (m :: k -> Type -> Type) (id :: k) | m -> id where
pempty :: PUnary m id a
class PAlternative (m :: k -> Type -> Type) (t :: k) (u :: k) (v :: k) | t u -> v where
pappend :: PUnary m t a -> PUnary m u a -> PUnary m v a
(&<|>) :: (PAlternative m t u v) => PUnary m t a -> PUnary m u a -> PUnary m v a
(&<|>) = pappend
infixl 3 &<|>
infixl 3 `pappend`