DEV Community

Discussion on: Grokking the Reader Monad

Collapse
 
choc13 profile image
Matt Thornton • Edited

Thanks for pointing out those typos, my editorial team obviously missed them 😂

You’re right to spot the similarity to the State monad. I believe the State monad is basically the Reader + Writer monads. So the State monad allows you to modify the state too (by creating a new copy with the modifications) as well as read from it. So yeah if we combine Reader + Writer then we get State.

On the inferred inheritance point then I believe in Haskell it would be done with type classes. I believe this is more commonly referred to as the MTL style. I’ve not done any large scale Haskell projects so I wouldn’t want to give an example here as I suspect I’ll make a mistake, but if you look into type classes and MTL then I think that will give you the answer.

I also plan to do more on how to achieve IoC in FP later in this series after I’ve introduced a few more fundamentals. In that I’ll try and provide a more production ready version of inferred inheritance and also some other ways of grouping dependencies together. As just using it like I’ve introduced it here probably won’t scale too well for large code bases. That’s not to say it’s not a useful technique it just requires a bit of a longer treatment than I could fit into this post.