Make the Plan a Value
The article discusses how the author implemented idempotency tokens in the Amazonka Haskell AWS SDK. To achieve this, they introduced a "plan" concept, separating the decision-making process from the execution phase. This decoupling simplifies testing and makes the codebase more manageable. The author likens this approach to the "plan-execute" pattern and "routing slip" integration pattern.
They introduce a Config record and a function called instanceD to build Haskell code from this plan type. The generator's logic was refactored incrementally, starting with response parsing. The idea is to keep a "do it the old way" constructor in the plan type until the old method has been refactored. This technique allows for alternate consumers of the plan, such as testability, --dry-run, and simpler executors.
The author also highlights that Haskell's laziness makes this approach particularly convenient, but the benefits apply to other languages as well.
Rewritten by urgent.news; may contain errors — check the original.
Source: jackkelly.name