diff --git a/lib/effect.fz b/lib/effect.fz
index d43e5bd5f..33eacaee0 100644
--- a/lib/effect.fz
+++ b/lib/effect.fz
@@ -33,7 +33,7 @@ module:public effect (
# action to be performed, may include code to run while this effect is installed.
#
r effect_mode.val
- )
+ ) : Effect
is
match r
@@ -153,6 +153,23 @@ is
set res := f()
+ public redef exec(R type, f () -> R) option R =>
+ cf := Effect_Call f
+ abortable cf
+ cf.res
+
+
+public Effect ref is
+ public exec(R type, f () -> R) option R => abstract
+
+
+public with(T type, effects Sequence Effect, code ()->T) option T =>
+ if effects.is_empty
+ code.call
+ else
+ effects.first.exec ()->(with (effects.drop 1) code)
+
+
# effect mode is an enum that determines how an instance of effect is used
#
public effect_mode is
ex is
greeter (greet String->unit) : simple_effect is
_ := with [greeter (x -> say "Hello, $x!")] ()->
greeter.env.greet "World"
leads to:
$MODULE/option.fz:161:27: error 1: Failed to verify that effect 'try (option (option unit))' is installed in current environment.
| nil => (try (option T)).env.raise (error "error unwrapping option: {option.this}")
--------------------------^^^^^^^^^^^^^^^^^^^
Callchain that lead to this point:
effect environment '--empty--' for call to '(option (option unit)).unwrap' at $MODULE/effect.fz:170:19:
effects.first.exec ()->(with (effects.drop 1) code)
------------------^^^^
effect environment '--empty--' for call to 'with unit' at /home/sam/playground/test.fz:5:8:
_ := with [greeter (x -> say "Hello, $x!")] ()->
-------^^^^
effect environment '--empty--' for call to 'ex'
effect environment '--empty--' at program entry
/home/sam/playground/test.fz:6:5: error 2: Failed to verify that effect 'ex.greeter' is installed in current environment.
greeter.env.greet "World"
----^^^^^^^^^^^
Callchain that lead to this point:
effect environment '--empty--' for call to 'ex.fun.call' at $MODULE/effect.fz:168:10:
code.call
---------^^^^
effect environment '--empty--' for call to 'with unit' at /home/sam/playground/test.fz:5:8:
_ := with [greeter (x -> say "Hello, $x!")] ()->
-------^^^^
effect environment '--empty--' for call to 'ex'
effect environment '--empty--' at program entry
2 errors.
but when commenting the error in DfaErrors.java the code executes just fine.
leads to:
but when commenting the error in DfaErrors.java the code executes just fine.