Many monad transformers in Haskell add only one function to the base monad, for example:
MaybeT adds mzero
ExceptT adds throwE
Producer adds yield
Consumer adds await
So, in a IO
- heavy or complex nested monad, I would usually end up writing do
-block, like this
do
liftIO $ ...
liftIO $ ...
if ...
then
liftIO $ ...
else
mzero
liftIO $ ...
liftIO $ ...
liftIO $ ...
which is very unnecessary, as I probably just use a mzero
specific operator for this. Wouldn't it be nice if I could instead “unlock” it when necessary and write the rest of the block normally? Imagine what I could write
lift $ do
...
...
if ...
then
...
else
unlift $ mzero
...
...
...
, , do
- , , - Haskell?