|
11 | 11 | from effectful.ops.types import Expr, Interpretation, NotHandled, Operation, Term |
12 | 12 |
|
13 | 13 |
|
14 | | -@defop |
15 | | -def apply(intp: Interpretation, op: Operation, *args, **kwargs) -> Any: |
| 14 | +@defop # type: ignore |
| 15 | +def apply[**P, T](op: Operation[P, T], *args: P.args, **kwargs: P.kwargs) -> T: |
16 | 16 | """Apply ``op`` to ``args``, ``kwargs`` in interpretation ``intp``. |
17 | 17 |
|
18 | 18 | Handling :func:`apply` changes the evaluation strategy of terms. |
@@ -41,14 +41,15 @@ def apply(intp: Interpretation, op: Operation, *args, **kwargs) -> Any: |
41 | 41 | mul(add(1, 2), 3) |
42 | 42 |
|
43 | 43 | """ |
44 | | - from effectful.internals.runtime import interpreter |
| 44 | + from effectful.internals.runtime import get_interpretation |
45 | 45 |
|
| 46 | + intp = get_interpretation() |
46 | 47 | if op in intp: |
47 | | - return interpreter(intp)(intp[op])(*args, **kwargs) |
| 48 | + return intp[op](*args, **kwargs) |
48 | 49 | elif apply in intp: |
49 | | - return intp[apply](intp, op, *args, **kwargs) |
| 50 | + return intp[apply](op, *args, **kwargs) |
50 | 51 | else: |
51 | | - return op.__default_rule__(*args, **kwargs) |
| 52 | + return op.__default_rule__(*args, **kwargs) # type: ignore |
52 | 53 |
|
53 | 54 |
|
54 | 55 | @defop # type: ignore |
@@ -208,7 +209,7 @@ def runner(intp: Interpretation): |
208 | 209 | from effectful.internals.runtime import get_interpretation, interpreter |
209 | 210 |
|
210 | 211 | @interpreter(get_interpretation()) |
211 | | - def _reapply[**P, S](_, op: Operation[P, S], *args: P.args, **kwargs: P.kwargs): |
| 212 | + def _reapply[**P, S](op: Operation[P, S], *args: P.args, **kwargs: P.kwargs): |
212 | 213 | return op(*args, **kwargs) |
213 | 214 |
|
214 | 215 | with interpreter({apply: _reapply, **intp}): |
@@ -316,7 +317,7 @@ def typeof[T](term: Expr[T]) -> type[T]: |
316 | 317 | """ |
317 | 318 | from effectful.internals.runtime import interpreter |
318 | 319 |
|
319 | | - with interpreter({apply: lambda _, op, *a, **k: op.__type_rule__(*a, **k)}): |
| 320 | + with interpreter({apply: lambda op, *a, **k: op.__type_rule__(*a, **k)}): |
320 | 321 | if isinstance(term, Term): |
321 | 322 | # If term is a Term, we evaluate it to get its type |
322 | 323 | tp = evaluate(term) |
@@ -353,7 +354,7 @@ def fvsof[S](term: Expr[S]) -> set[Operation]: |
353 | 354 |
|
354 | 355 | _fvs: set[Operation] = set() |
355 | 356 |
|
356 | | - def _update_fvs(_, op, *args, **kwargs): |
| 357 | + def _update_fvs(op, *args, **kwargs): |
357 | 358 | _fvs.add(op) |
358 | 359 | arg_ctxs, kwarg_ctxs = op.__fvs_rule__(*args, **kwargs) |
359 | 360 | bound_vars = set().union( |
|
0 commit comments