Exotic Programming Ideas, Part 3: Effect Systems
I&#x27;ve had this idea of &quot;dynamic returns&quot; (akin to dynamic scope) in my head for a while. Reading this, it feels like a dynamically typed companion to effect systems.<p>The idea of a dynamic return is just to give a formal way to accumulate things during a set of function calls, without having every function to be aware of what might be happening. In Python context managers are often used for this (e.g., contextlib.redirect_stdout to capture stdout), but thinking about it as another kind of return value instead of &quot;capturing&quot; would be an improvement IMHO. (You have to &quot;capture&quot; when hardcoded imperative code later needs to be retrofitted, but as it is retrofitting is all we have.)<p>But dynamic returns aren&#x27;t quite like an effect system unless you also create something more-or-less like a transaction or a changeset. We usually think about transactions as simply a way to rollback in case of an error, but as a changeset there&#x27;s all kinds of interesting auditing and logging and debugging possibilities. E.g., if your effect is writing to stdout, you could rewrite all those changes (e.g., apply a filter, or add a text prefix to each line).