Definition KSApplicative (i j : Type) : Applicative.
exists (KleeneStore i j) (KSpure i j) (@KSap i j).
apply KSpure_id.
apply composition_KS.
apply KSpure_KSpure.
apply interchange_KSpure.
Defined.
Section ComposeApplicative.
Variable (F G :Applicative).
Let FG (a:Type) := F (G a).
Definition Compose_pure (a:Type) (x:a) : FG a :=
pure F (pure G x).
Definition Compose_ap (a b:Type) (f:FG (a -> b)) (x:FG a) : FG b :=
ap (ap (pure F (fun g x => ap g x)) f) x.

(* Specifications: *)
Lemma Compose_identity (a:Type) (x : FG a):
Compose_ap (Compose_pure (fun y : a => y)) x = x.
Lemma Compose_composition (a b c:Type) x y (z : FG a) :
Compose_ap (Compose_ap (Compose_ap (Compose_pure (fun (f : b -> c) (g : a -> b) (w:a) => f (g w)))
x) y) z =
Compose_ap x (Compose_ap y z).
Lemma Compose_homomorphism a b (f : a -> b) x :
Compose_ap (Compose_pure f) (Compose_pure x) = Compose_pure (f x).
Lemma Compose_interchange a b (f : FG (a -> b)) x :
Compose_ap f (Compose_pure x) = Compose_ap (Compose_pure (fun g => g x)) f.