Stack monad stack

So, I have this code in my entire first major haskell project:

f :: (MonadTrans t) => ExceptT () (t (StateT A B)) C
f = do mapExceptT lift $ do
    lift $ do
        ...
        lift $ do
            ...
            r <- ...
            ...
            return r
    >>= \r -> ...

There may definitely be something wrong with how I am trying to achieve my goals (there may be simpler ways to do this), but at the moment I am interested to know how best to handle a stack of monad transformers, if there is one. This is the only way to figure out how to get rin context Band raise it to the monad higher in the stack. Raising whole blocks instead of the initial instructions is how much I can handle myself.

What I also often end up with is the chains liftthat I found out about that can be avoided with liftIO, if a deep monad IO. However, I do not know a common path for other monads.

, , , - , , , , ?

- , ( , let ), lift . lift . ... lift ?

+4
2

. , "". :

  • mtl, ( ). f :: (MonadState A m, MonadError () m) => m C, , . - mtl -. . gory.
  • , , newtype , . Functor, Applicative, Monad , , GeneralizedNewtypeDeriving, ; lift . , , ​​ , mtl. , "-" , , - .
  • , " A" " ". , , , . , Functor, Applicative Monad, newtype 'd. , : . , .
  • - . , Haskell. . -.
+6

- mtl, transformers. , t, mtl ,

foo :: (MonadError e m, MonadState s m) => m Int

. , newtype, , .

( ), mtl , . . , ; , .

+4

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


All Articles