Getting into nested monad transformers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting into nested monad transformers

Arthur Chan
Hey all,

I've been trying to access the inner state "s" for this type:

newtype TestThingey s a = TestThingey {
      runTrans :: ReaderT Int (StateT String (StateT s IO)) a
} deriving (Monad, MonadIO, MonadState String, MonadReader Int)

It doesn't seem to be doable.  I could make it into a regular type
declaration, but then I lose the GeneralizedNewtypeDeriving.  Is this
common?  Or do people just avoid needing to use "lift"?

-Arthur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090219/fae704c3/attachment-0001.htm
Reply | Threaded
Open this post in threaded view
|

Getting into nested monad transformers

Brent Yorgey-2
On Thu, Feb 19, 2009 at 09:51:06PM -0800, Arthur Chan wrote:
> Hey all,
>
> I've been trying to access the inner state "s" for this type:
>
> newtype TestThingey s a = TestThingey {
>       runTrans :: ReaderT Int (StateT String (StateT s IO)) a
> } deriving (Monad, MonadIO, MonadState String, MonadReader Int)

In this situation I would combine the String and s into one state:

  ReaderT Int (StateT (String,s) IO) a

Otherwise, yes, you'll just have to use the appropriate number of
lifts.

-Brent