aboutsummaryrefslogtreecommitdiff
path: root/examples/31-effect-handler-nested
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-02-02 20:13:05 +0000
committerMichael Williamson <mike@zwobble.org>2025-02-02 20:13:20 +0000
commit89394d0fab076765b637b0fe643d8f8950639817 (patch)
tree6852b4f81fd7f7812bb208df52b4e0cc8b1bcbdf /examples/31-effect-handler-nested
parent67f010c93b11744b1f2f1c9403fd1e8d2b888acb (diff)
Add int arithmetic example
Diffstat (limited to 'examples/31-effect-handler-nested')
-rw-r--r--examples/31-effect-handler-nested/shed-examples.json59
-rw-r--r--examples/31-effect-handler-nested/shed.json58
-rw-r--r--examples/31-effect-handler-nested/src/Example.shed42
3 files changed, 59 insertions, 0 deletions
diff --git a/examples/31-effect-handler-nested/shed-examples.json5 b/examples/31-effect-handler-nested/shed-examples.json5
new file mode 100644
index 00000000..13ea0b50
--- /dev/null
+++ b/examples/31-effect-handler-nested/shed-examples.json5
@@ -0,0 +1,9 @@
+{
+ examples: [
+ {
+ project: ".",
+ bin: "example",
+ expectedOutput: "a outer\na inner\na inner\nb\na inner\na inner\na outer",
+ },
+ ],
+}
diff --git a/examples/31-effect-handler-nested/shed.json5 b/examples/31-effect-handler-nested/shed.json5
new file mode 100644
index 00000000..e642a813
--- /dev/null
+++ b/examples/31-effect-handler-nested/shed.json5
@@ -0,0 +1,8 @@
+{
+ bins: [
+ {
+ name: "example",
+ mainNamespace: "Example",
+ },
+ ],
+}
diff --git a/examples/31-effect-handler-nested/src/Example.shed b/examples/31-effect-handler-nested/src/Example.shed
new file mode 100644
index 00000000..2a8e4781
--- /dev/null
+++ b/examples/31-effect-handler-nested/src/Example.shed
@@ -0,0 +1,42 @@
+effect A {
+ fun a() -> Unit;
+}
+
+effect B {
+ fun b() -> Unit;
+}
+
+pub fun main() ! Io -> Unit {
+ try {
+ A.a!();
+
+ try {
+ A.a!();
+
+ try {
+ A.a!();
+ B.b!();
+ A.a!();
+ } handle B {
+ fun b() {
+ print!("b\n");
+ resume;
+ }
+ }
+
+ A.a!();
+ } handle A {
+ fun a() {
+ print!("a inner\n");
+ resume;
+ }
+ }
+
+ A.a!();
+ } handle A {
+ fun a() {
+ print!("a outer\n");
+ resume;
+ }
+ }
+}