[Haskell-beginners] StateT MyState IO a vs ReaderT (IORef MyState) IO a
Michael Snoyman
michael at snoyman.com
Sat Apr 18 19:12:22 UTC 2015
I actually released a library a week or two back that uses this trick:
https://github.com/fpco/monad-unlift#reference-transformers
The main advantage in my mind is that the state survives exceptions.
On Sat, Apr 18, 2015 at 12:09 PM Konstantin Saveljev <
konstantin.saveljev at gmail.com> wrote:
> Hello,
>
> I'm working on a project where I use StateT MyState IO a to keep track of
> the state. MyState is deeply nested and I use lens to help me more easily
> access and modify the state.
>
> Just about yesterday I found someone mentioning about using ReaderT (IORef
> MyState) IO a instead of StateT MyState IO a because we are already in IO.
>
> Can someone explain to me what are the benefits of these different
> approaches? What about Garbage Collection in both cases (if there is any
> difference at all)? Can you use lens package to access and update the state
> which is hidden behind IORef ?
>
> Thanks,
> Konstantin Saveljev
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150418/cfc6bf26/attachment-0001.html>
More information about the Beginners
mailing list