After getting more and more comfortable with cats’ state monad I decided to publish a simple tutorial about how to use it. I am confident everybody knows about’s fp book, yes? In that book we find simple instructions on how to use the state monad - the final exercise on it closes with a tiny parser and interpreter for RPN expressions. If you’ve read that chapter (and even did that final exercise, too) you should be ready to jump in!

The simple task we’ll try to accomplish is this:

  1. as input we get a list of roman characters e.g. List(X, M, I, D, M)
  2. we want to inspect that list pairwise: if the first character is greater than or equal to the second we create an “addition expression”, otherwise an “subtraction expression”.
  3. as output we want a list of expressions e.g. List(ExprPlus, ExprMinus, ExprLiteral)

You can find the final code from the tutorial on my