multistate: like mtl's ReaderT/StateT, but more than one contained value/type.

[ bsd3, control, library ] [ Propose Tags ]


When using multiple ReaderT's or StateT's in the same monad stack, it becomes necessary to lift the operations in order to affect a specific transformer. Using heterogenous lists (type level functions), a GADT and a corresponding type class, this package provides transformers that remove that necessity: MultiReaderT/MultiStateT can contain a heterogenous list of values.

The type inferred for the getter/setter determines which value is read/written.


             -- an IO action wrapped by a MultiState
             -- containing both a Char and a [Char].
examplePrint :: MultiStateT (Cons [Char] (Cons Char Null)) IO ()
examplePrint = do
  c  <- mGet             -- inferred to be :: m Char
  cs <- mGet             -- inferred to be :: m [Char]
  lift $ putStrLn (c:cs)

This computation can be executed in the following way:

main = evalMultiStateT
     $ withMultiState 'H'
     $ withMultiState "ello, World!"
     $ examplePrint

the output is:

Hello, World!
Jello, World!

( you can find both this and a more complex example in an executable in the package. )

Error Messages

If you try to execute an action that requires a specific type in the state, but the current state does not contain that type, the error message is something like

Control.Monad.MultiState.ContainsType Foo Null

where Foo is the missing type.

Known Deficits

This package currently lacks a complete set of "lifting instances", i.e. instance definitions for classes such as mtl's MonadWriter "over" the newly introduced monad transformers, as in

instance (MonadWriter w m) => MonadWriter w (MultiStateT c m) where ..

These "lifting instances" would be necessary to achieve full compatability with existing transformers. Ping me if you find anything specific missing.

Versions [faq] 0.1.1, 0.1.2,,,,,,,,,,,,,
Dependencies base (>=4.6 && <4.8), mtl (>=2.1 && <2.3), multistate, tfp (==0.8.*), transformers (>=0.3 && <0.5) [details]
License BSD-3-Clause
Copyright Jan Bracker, Lennart Spitzner
Author Jan Bracker, Lennart Spitzner
Maintainer Lennart Spitzner <>
Category Control
Home page
Bug tracker
Source repo head: git clone
Uploaded by lspitzner at Wed Sep 17 15:30:30 UTC 2014
Distributions NixOS:, Stackage:
Executables multistate-example, multistate-test
Downloads 9119 total (560 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]





Build the MultiState-test test program


Build the MultiState-example example program


Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees