Skip to content

Commit 4c49b4c

Browse files
authored
Fix evaluation of operations that return reducible terms (#293)
* correctly evaluate operations that return reducible terms * switch to interpreter
1 parent 5a579b4 commit 4c49b4c

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

effectful/ops/semantics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def apply(intp: Interpretation, op: Operation, *args, **kwargs) -> Any:
4646
mul(add(1, 2), 3)
4747
4848
"""
49+
from effectful.internals.runtime import interpreter
50+
4951
if op in intp:
50-
return intp[op](*args, **kwargs)
52+
return interpreter(intp)(intp[op])(*args, **kwargs)
5153
elif apply in intp:
5254
return intp[apply](intp, op, *args, **kwargs)
5355
else:

tests/test_ops_semantics.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
runner,
2020
typeof,
2121
)
22-
from effectful.ops.syntax import ObjectInterpretation, Scoped, defop, implements
22+
from effectful.ops.syntax import ObjectInterpretation, Scoped, deffn, defop, implements
2323
from effectful.ops.types import Interpretation, Operation
2424

2525
logger = logging.getLogger(__name__)
@@ -756,3 +756,17 @@ def box_value(x: T) -> Box[T]:
756756

757757
# Generic types are simplified to their origin type
758758
assert typeof(box_value(42)) is Box
759+
760+
761+
def test_evaluate_deep():
762+
x, y, z = defop(int), defop(int), defop(int)
763+
intp = {x: deffn(1), y: deffn(2), z: deffn(x() + y())}
764+
765+
with handler(intp):
766+
assert z() == 3
767+
768+
assert handler(intp)(z)() == 3
769+
770+
assert evaluate(evaluate(z(), intp=intp), intp=intp) == 3
771+
772+
assert evaluate(z(), intp=intp) == 3

0 commit comments

Comments
 (0)