Sometimes I need to use several nested MonadTrans
. For example, I would put a MaybeT
inside of a ExceptT
, to mimick continue
and break
in imperative programming:
runExceptT . forM [1..] $ \ _ -> runMaybeT $ do
...
mzero -- this mimics continue
lift $ throwE "..." -- this mimics break
lift . lift $ putStrLn "Hello!"
...
However, as the above code shows, every time I need to do any IO
inside of this "artificial loop", I need to put an ugly lift . lift
before it. Imagine if I have even more complicated nestings, and a lot of IO
operations, this quickly becomes an anonyance. How I make the code cleaner and more concise?