## Composing Applicative and Alternative

July 8th, 2007 by ConorNicolas asked whether the composition (either way around) of an Applicative functor

and an Alternative functor

was necessarily Alternative (of course, both f⋅g and g⋅f are Applicative). The answer is yes, both are Alternative. Firstly, g⋅f is Alternative, just by specialising g’s operations. Secondly, f⋅g is Alternative just by the usual idiomatic f-lifting of g’s operations. The applicative functor laws guarantee that the f-effects are combined associatively.

In the hunt for interesting non-monadic examples, we were drawn once again to

These things are not monadic like lists-with-‘nondeterminism’: the join

is not productive (what should do? These things are not monadic like streams-with-‘diagonal’ (raggedness breaks associativity of joining). But they are Applicative in the ‘minimum-diagonal’ sense

They are also alternative