Abstracting monad composition as a transformer
-
30-10-2019 - |
Question
Sorry if the question seems a bit trivial... it is not for me. I have happily composed the following monad:
type SB i a = ReaderT ( AlgRO i ) (State ( AlgState i ) ) a
which is, well, a well behaved monad. ReaderT is a monad transformer and State is the State monad, and AlgRO and AlgState are datatypes parametrized in i for mutable and read-only state, respectively. Now, if I want to make of that a neat monad transformer with newtype, something like this:
newtype SbT m i a = SbT {
runSbT:: m ( SB i a )
}
how should I proceed? I can not even manage to put together the bind method (of Monad typeclass), much less "lift" (of MonadTrans)... I guess that automatic derivation could help, but I want to understand how it works in this case.
Thanks in advance.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow