[Haskell-cafe] advice: instantiating/duplicating modules

Nicolas Frisby nicolas.frisby at gmail.com
Fri Jun 29 13:07:38 EDT 2007

I wrote a combination reader/writer monad (a la the RWS monad in the
mtl) and I find myself wanting to use multiple instances of it in the
same stack of transformers. The functional dependencies prevent this
from working out. The class is called MonadRW and the transformer is
called RWT.

I find myself wishing I could import the same module twice, but
instead of having two names for the same entity, I want the
definitions proper of the module to be duplicated: I want two separate
MonadRW classes and two separate RWT transformers. Since the module
integrates the MonadRW and RWT transformer with the mtl, I would then
only need to lift the instances of the instantiated MonadRW classes
through the other RWTs.

I'm rather unfamiliar with Template Haskell, but it sounds like it
might fit the bill. Although, if I recall correctly, instances and
type declarations splicing are yet to be implemented in GHC?

Does anyone have any advice how to do this? I'm envisioning some
preprocessing. I'd like to know if someone has developed a tool for
this already or if this path has been attempted.

Thanks for your time,

PS - If this doesn't work out, I'm aware that I could use type-indexed
products and coproducts to pull it off, but I think that would
drastically reduce the number of  people who could understand/maintain
the code without having to learn such cool stuff.

More information about the Haskell-Cafe mailing list