ExtLib.Structures.Applicative

Set Implicit Arguments.
Set Maximal Implicit Insertion.
Set Universe Polymorphism.

Class PApplicative@{d c p} (T : Type@{d} -> Type@{c}) :=
{ AppP : Type@{d} -> Type@{p}
; ppure : forall {A : Type@{d}} {P : AppP A}, A -> T A
; pap : forall {A B : Type@{d}} {P : AppP B}, T (A -> B) -> T A -> T B
}.

Class Applicative@{d c} (T : Type@{d} -> Type@{c}) :=
{ pure : forall {A : Type@{d}}, A -> T A
; ap : forall {A B : Type@{d}}, T (A -> B) -> T A -> T B
}.

Module ApplicativeNotation.
  Notation "f <*> x" := (ap f x) (at level 52, left associativity).
End ApplicativeNotation.
Import ApplicativeNotation.

Section applicative.
  Definition liftA@{d c} {T : Type@{d} -> Type@{c}} {AT:Applicative@{d c} T} {A B : Type@{d}} (f:A -> B) (aT:T A) : T B := pure f <*> aT.
  Definition liftA2@{d c} {T : Type@{d} -> Type@{c}} {AT:Applicative@{d c} T} {A B C : Type@{d}} (f:A -> B -> C) (aT:T A) (bT:T B) : T C := liftA f aT <*> bT.
End applicative.