The following test should pass:
from effectful.ops.semantics import apply, fwd, handler
from effectful.ops.types import Operation
@Operation.define
def f(x: int) -> int:
return x + 1
f_handler_calls = 0
apply_handler_calls = 0
def _f_handler(x):
global f_handler_calls
f_handler_calls += 1
return fwd()
def _apply_handler(op, *args, **kwargs):
global apply_handler_calls
apply_handler_calls += 1
return fwd()
with handler({apply: _apply_handler}), handler({f: _f_handler}):
assert f(1) == 2
assert f_handler_calls == 1
assert apply_handler_calls == 1
Apply handlers are often used as catch-all handlers to implement tracing or similar global effects. This doesn't work right now unless the traced effects are otherwise unhandled.
The following test should pass:
Apply handlers are often used as catch-all handlers to implement tracing or similar global effects. This doesn't work right now unless the traced effects are otherwise unhandled.