Is there a way to use the “fuzzy” style when recording in a monodal transformer is blocked?

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 mzerospecific 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?

+4

Source: https://habr.com/ru/post/1612643/


All Articles