The multistate package

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.


== Introduction

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.

== Example

 simpleExample :: IO ()
 simpleExample = evalMultiStateT
               $ withMultiState 'H'
               $ withMultiState "ello, World!"
               $ do
   -- the monad here is MultiStateT '[String, Char] IO
   let combinedPrint = do       -- no type signature necessary
         c  <- mGet             -- type of mGet inferred to be m Char
         cs <- mGet             --              inferred to be m String
         lift $ putStrLn (c:cs)
   mSet 'J'                     -- similarly for the setter

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

 No instance for (Control.Monad.MultiState.ContainsType Foo '[])

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.

== Changelog

 Null        -> '[]
 Cons a Null -> '[a]
 Cons a b    -> a ': b
 TNull       -> HNil
 TCons a b   -> a :+: b


Versions0.1.1, 0.1.2,,,,,,,,,,
Change logNone available
Dependenciesbase (>=4.6 && <4.8), mtl (>=2.1 && <2.3), multistate, transformers (>=0.3 && <0.5) [details]
CopyrightJan Bracker, Lennart Spitzner
AuthorJan Bracker, Lennart Spitzner
MaintainerLennart Spitzner <>
Home page
Bug tracker
Source repositoryhead: git clone
Executablesmultistate-example, multistate-test
UploadedWed Jan 21 23:15:16 UTC 2015 by lspitzner




build-testBuild the MultiState-test test programDisabledAutomatic
build-exampleBuild the MultiState-example example programDisabledAutomatic

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


Maintainers' corner

For package maintainers and hackage trustees