I've written the following monad transformers (which I believe are equivalent to each other), namely:
newtype MonadReaderT1 r m a = MonadReaderT (ReaderT (r m) m a)
newtype MonadReaderT2 r m a = MonadReaderT (ReaderT (m r) m a)
The purpose of these is that I basically want a ReaderT
, but my environment has to be accessed inside the Monad, it's not actually a fixed pure value (in my case, it's an auth token that needs to be periodically refreshed).
The reason why I think MonadReaderT1
and MonadReaderT2
are equivalent, because I can just go:
newtype B m = B (m A)
And then MonadReaderT1 B
is the same as MonadReaderT2 A
.
But I think I need this extra machinery here above and beyond what I get with plain old ReaderT
.
But I get the feeling I'm not the first person to have done this or needed this. Have I just reinvented an existing type, and if so what is it?