This document discusses the differences between using yield and return in computation expressions in F#. It presents several implementations of computation expressions to demonstrate how yield and return can be distinguished. The key differences are:
- yield continues the remaining computation expression, while return stops any remaining expressions from executing.
- Several approaches are presented: using exceptions, a state field on the builder, and passing state as an argument. The state argument approach provides a clear separation of yield and return without sharing state between uses of the builder.
- Continuations are also proposed as an implementation, where yield calls the continuation and return discards it. This approach makes the symmetry between yield and return very clear.