Notes
This article was translated by GPT-5.2-Codex. The original is here.
This time I looked at the Reader monad and implemented the sample from the Reader monad page of All About Monads using Cats. I just started using Cats so there may be a better way to write it, but it works for now, so I’ll just post the code.
I think Cats MTL could make some parts more readable.
Compared to the Haskell code, the following points were different.
- Haskell's
askscorresponds toReaderT.ask[Id, _].map(...)in Scala- There is no equivalent to
asks(maybe?)
- There is no equivalent to
- Haskell's
mapMcorresponds totraversein Scala - Type inference doesn't work as well as in Haskell (maybe my style is not great) 😢
Since I rarely write this kind of code after starting work, I can’t help but think that procedural code might be clearer. So I plan to implement the same logic without the Reader monad and compare.