winitzki
winitzki

Reputation: 3347

Universal monad transformer for all monads?

The 2002 paper "Composing monads using coproducts" seems to describe the following type construction:

 Coprod R S a = ∀(T : Monad) → (∀b. R b → T b) → (∀b. S b → T b) → T a

Here R, S are lawful monads, and also the functions of types ∀b. R b → T b and ∀b. S b → T b are required to be lawful monad morphisms.

The paper does not show this construction explicitly but indicates it in words.

The cited paper's explicit results are limited to a certain subset of monads and, in particular, do not apply to the Reader monad, the State monad, the Continuation monad, the Selector monad, or the Codensity monad.

But it seems that Coprod is a general construction that can completely replace the need for building monad stacks via monad transformers.

Questions

  1. For a fixed monad R, is Coprod R a universal way of constructing R's monad transformer? If so, why aren't we using it, instead of complicated and limited monad transformers?
  2. The paper showed that Coprod is equivalent to standard transformers for certain monads such as Maybe, Writer, and Either. Does Coprod R S lead to different monad transformers than the known ones for standard monads (Reader, State, Continuation, etc.)?
  3. Did anyone implement this Coprod in a library, or was that paper completely ignored? If so, why?

What I can figure out

So, it appears that Coprod is a nice, well-behaved construction that has all the nice properties one might wish for a monad transformer. (Not all standard monad transformers have all those properties. For instance, the continuation monad's standard transformer is not an endofunctor in the category of monads.)

The Coprod R S constructor can be straightforwardly generalized to more monads (like, Coprod R S T U and so on). This construction seems to replace the need for monad stacks.

Remarks

Upvotes: 0

Views: 47

Answers (0)

Related Questions