|
| |||
|
|
Some monads do not have a corresponding monad transformer? So far there seem to exist two classes of monads that have no monad transformers: 1. P a = Either (m a) a Here `m` must be another monad, for example `m = Reader` or `m = State` or whatever. This construction produces a monad `P` for any monad `m`. The monad `P` is mostly the same as `m` except its "pure value" is explicitly represented as `Right x`. However, the resulting monad `P` does not seem to have a monad transformer. I tried all kinds of type expressions involving `Either` and `m`, but couldn't make it work, even with the simplest example `m = Reader`. 2. S a = (a -> Bool) -> Maybe a This is the so-called "search monad". It takes a predicate `a -> Bool` and possibly produces a value of `a` that satisfies the predicate. A generalization of the search monad is the so-called "selector" monad, S a = (a -> p ()) -> p a where `p` is another monad. The "search" monad is obtained with `p = Maybe`, since `Maybe ()` is equivalent to `Bool`. Even more generally, we can replace the unit type `()` with any constant type `c`. The result will be S a = (a -> p c) -> p a This is a monad for any fixed monad `p` and for any fixed type `c`. But this monad does not seem to have a monad transformer. For example `(m a -> p c) -> p (m a)` is not a monad for arbitrary monads `m`. I tried other type expressions involving `m` at different places, but nothing seems to work. So this for me seems to close the long-standing question of whether all monads have a monad transformer, and if so, how to construct one. The answer seems to be that some monads don't have a monad transformer, and for other monads there are ad hoc ways of constructing transformers. However, I still don't know how to prove rigorously that no transformer exists for a given monad. |
||||||||||||||