One of the problems with monad transformers I find is the need to lift
the operations into the right monad. A single lift
here and there isn't bad, but sometimes there are functions that looks like this:
fun = do
lift a
lift b
c
lift d
lift e
f
I would like to be able to write this function thus:
fun = monadInvert $ do
a
b
lift c
d
e
lift f
This halves the number of lift
s and makes the code cleaner.
The question is: for what monads is monadInvert
possible? How should one create this function?
Bonus points: define it for monad m
which is an instance of MonadIO
.
The title of this question speaks of permutations: indeed, how can we deal with arbitrary permutations of a monad tranformer stack?