Skip to content

Apply handlers should be possible targets of fwd #759

Description

@jfeser

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions