3 ms·
An effect system is like a type system, but keeps track of the 'effects' (think 'side effects', but we're doing them on purpose) that may occur when evaluating
by chriswarbo 8y ago
An effect system is like a type system, but keeps track of the 'effects' (think 'side effects', but we're doing them on purpose) that may occur when evaluating an expression. For example `print` might have a `log` effect. Unlike types, which get 'consumed' (e.g. by calling a function with an argument), effects tend to accumulate.
I've mostly seen effect systems in the form of 'algebraic effect handling', which allow effects to be "handled" in a similar way to try/catch for (resumable) exceptions. For example, if we have an expression with the `log` effect, our tests might wrap it in a handler which just accumulates a string, so we can test what was logged; our production system might use a handler that plugs into an external logging system (which would require an effect like 'IO' or 'socket' or something).
Stack languages like Forth and Kitten have "stack effects", which are the effects that evaluating an expression has on the stack, e.g. popping some values.
Effects are sort of the inverse of capabilities: an expression with effect E tells us "evaluating this expression might result in E happening", whilst an expression with capability C says "to evaluate this expression, you must allow me to C".