Hi,

Ömer Sinan Ağacan wrote:
One thing I'm not happy about my Haskell programs is, almost all of my
programs have a monad transformer stack consisting MonadError, MonadIO
and MonadState.

You can try to write most of your program in pure functions that are called from a few "main" functions in the monad. Or, if you need some but not all monadic actions in each function, you can use the following pattern:

  -- This helper function cannot cause monadic effects other than
  -- throwing errors. But it can be used in arbitrary monads that
  -- support throwing errors.
  helper :: MonadError MyError m => ... -> m ...
  helper = do ...

  -- Same but with only allowing IO, but other monadic actions
  other :: MonadIO m => ... -> m ...
  other = do ...

  -- we can use both functions in the same monad
  main = runMyStack $ do
    helper
    other

This way, you have some control over what effects are allowed where.

  Tillmann

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to