Simple calculator using TDD in F# (part-4)

Just as a (very) quick recap, I started from a simple Stack in part-1 and ended up creating a fully functioning RpnCalculator in part-2 and part-3. In this part, I will try to focus on two things-

Simple calculator using TDD in F# (part-3)

In this part, I will try to solve the problems that I have created in previous parts (part-2 and part-1). First of all, I will add the ability to return int, float and even errors a a result of evaluating RPN expression. So, I add a type, directly in the RpnCalculator module, called “RpnResult” and my calculate method now looks like this:

Simple calculator using TDD in F# (part-2)

In previous part, I created a generic stack which supports push and pop operation of “anything” along with a very unnecessary isEmpty method. In this part, I will try to do something useful with the stack and will try to create a calculator that can operate on Reverse Polish Notation (RPN). I will call it RpnCaluclator. However, unlike a simple stack, I don’t really have the requirement in mind. I guess, I will enrich the requirement for RpnCalculator as I go along, until I find it complete enough. But, before I start, I would like to clean up the previous stack implementation to use the F# type inference. After removing unnecessary type declarations, my stack implementation looks like:

Simple calculator using TDD in F# (part-1)

Difficulty level: newborn
Length: really long part-1 of a multi-part blog post