[Haskell-cafe] seeking guideline re modules and stacks of State Monad Transformers

Ali Razavi ali.razavi at gmail.com
Tue Jul 20 11:44:57 EDT 2010


I am working on a project that features a few modules with inter-dependent
states. It is expected that some of the modules import and use some of the
stateful functions from other modules, and simultaneously, need to manage
the state of their own.  I need to make a design choice as to whether I
should add the new modules' state as separate layesr by transforming the
monad transformer stack in each module, or create a separate module to
handle the amalgamation of all states with a single datatype. Both solutions
have salient issues. The latter, namely stacking more layers, can quickly
become unwieldy, whereas the former breaches encapsulation. Any better

To give it more of a concrete context, imagine the following:

module A where

type AState = State Int....

someAFunc :: a -> AState a
module B where

type BState = StateT Int AState ...

someBFunc :: b -> BState b

-- now I want module C to only have access to B's part of BState, but not
the A-related part
module C where

type CState = StateT Int BState

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100720/fed79b28/attachment.html

More information about the Haskell-Cafe mailing list