module Pandora.Pattern.Functor.Applicative (Applicative (..)) where
import Pandora.Core.Functor (type (:.), type (:=))
import Pandora.Pattern.Category (identity)
import Pandora.Pattern.Functor.Covariant (Covariant ((<$>), (<$)))
infixl 4 <*>, <*, *>
class Covariant t => Applicative t where
{-# MINIMAL (<*>) #-}
(<*>) :: t (a -> b) -> t a -> t b
apply :: t (a -> b) -> t a -> t b
apply f x = f <*> x
(*>) :: t a -> t b -> t b
x *> y = (identity <$ x) <*> y
(<*) :: t a -> t b -> t a
x <* y = y *> x
forever :: t a -> t b
forever x = x *> forever x
(<**>) :: Applicative u => t :. u := (a -> b) -> t :. u := a -> t :. u := b
f <**> x = (<*>) <$> f <*> x
(<***>) :: (Applicative u, Applicative v) => t :. u :. v := (a -> b)
-> t :. u :. v := a -> t :. u :. v := b
f <***> x = (<**>) <$> f <*> x
(<****>) :: (Applicative u, Applicative v, Applicative w)
=> t :. u :. v :. w := (a -> b)
-> t :. u :. v :. w := a
-> t :. u :. v :. w := b
f <****> x = (<***>) <$> f <*> x
instance Applicative ((->) e) where
(<*>) f g x = f x (g x)