[Haskell-cafe] Stacking monads - beginner design question

Johan Tibell johan.tibell at gmail.com
Wed Jan 30 04:01:59 EST 2008

> Are monad stacks with 3 and more monads common?
> How could an example implementation look like?

I found reading the xmonad code (http://code.haskell.org/xmonad/)
enlightening. The X monad definition can be found in

-- | The X monad, a StateT transformer over IO encapsulating the window
-- manager state
-- Dynamic components may be retrieved with 'get', static components
-- with 'ask'. With newtype deriving we get readers and state monads
-- instantiated on XConf and XState automatically.
newtype X a = X (ReaderT XConf (StateT XState IO) a)
    deriving (Functor, Monad, MonadIO, MonadState XState, MonadReader XConf)

-- Johan

More information about the Haskell-Cafe mailing list