From 027d73dea19c4154d27c77cd82dd4b28649cdf3f Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 12 Jan 2025 15:11:04 +0000 Subject: Support recursive project dependencies --- .../20-function-expression/shed-examples.json5 | 9 ----- examples/20-function-expression/shed.json5 | 8 ---- .../20-function-expression/src/HelloWorld.shed | 11 ------ .../hello-world/.gitignore | 1 + .../hello-world/shed.json5 | 13 +++++++ .../hello-world/src/HelloWorld.shed | 5 +++ .../message1/shed.json5 | 7 ++++ .../message1/src/Message1.shed | 3 ++ .../message2/shed.json5 | 2 + .../message2/src/Message2.shed | 1 + .../shed-examples.json5 | 9 +++++ .../shed-examples.json5 | 9 ----- .../shed.json5 | 8 ---- .../src/HelloWorld.shed | 4 -- .../21-function-expression/shed-examples.json5 | 9 +++++ examples/21-function-expression/shed.json5 | 8 ++++ .../21-function-expression/src/HelloWorld.shed | 11 ++++++ .../shed-examples.json5 | 9 ----- .../shed.json5 | 8 ---- .../src/HelloWorld.shed | 8 ---- .../shed-examples.json5 | 9 +++++ .../shed.json5 | 8 ++++ .../src/HelloWorld.shed | 4 ++ examples/23-effect-resume/shed-examples.json5 | 9 ----- examples/23-effect-resume/shed.json5 | 8 ---- examples/23-effect-resume/src/HelloWorld.shed | 23 ----------- .../shed-examples.json5 | 9 +++++ .../shed.json5 | 8 ++++ .../src/HelloWorld.shed | 8 ++++ .../shed-examples.json5 | 9 ----- examples/24-effect-resume-with-value/shed.json5 | 8 ---- .../src/HelloWorld.shed | 21 ----------- examples/24-effect-resume/shed-examples.json5 | 9 +++++ examples/24-effect-resume/shed.json5 | 8 ++++ examples/24-effect-resume/src/HelloWorld.shed | 23 +++++++++++ .../shed-examples.json5 | 9 +++++ examples/25-effect-resume-with-value/shed.json5 | 8 ++++ .../src/HelloWorld.shed | 21 +++++++++++ examples/25-effect-with-state/shed-examples.json5 | 9 ----- examples/25-effect-with-state/shed.json5 | 8 ---- examples/25-effect-with-state/src/HelloWorld.shed | 22 ----------- examples/26-effect-handler-pop/shed-examples.json5 | 9 ----- examples/26-effect-handler-pop/shed.json5 | 8 ---- examples/26-effect-handler-pop/src/HelloWorld.shed | 36 ------------------ examples/26-effect-with-state/shed-examples.json5 | 9 +++++ examples/26-effect-with-state/shed.json5 | 8 ++++ examples/26-effect-with-state/src/HelloWorld.shed | 22 +++++++++++ .../shed-examples.json5 | 9 ----- .../27-effect-handler-pop-on-return/shed.json5 | 8 ---- .../src/HelloWorld.shed | 41 -------------------- examples/27-effect-handler-pop/shed-examples.json5 | 9 +++++ examples/27-effect-handler-pop/shed.json5 | 8 ++++ examples/27-effect-handler-pop/src/HelloWorld.shed | 36 ++++++++++++++++++ .../28-effect-handler-nested/shed-examples.json5 | 9 ----- examples/28-effect-handler-nested/shed.json5 | 8 ---- examples/28-effect-handler-nested/src/Example.shed | 42 --------------------- .../shed-examples.json5 | 9 +++++ .../28-effect-handler-pop-on-return/shed.json5 | 8 ++++ .../src/HelloWorld.shed | 41 ++++++++++++++++++++ .../29-effect-handler-nested/shed-examples.json5 | 9 +++++ examples/29-effect-handler-nested/shed.json5 | 8 ++++ examples/29-effect-handler-nested/src/Example.shed | 42 +++++++++++++++++++++ examples/29-effect-in-handler/shed-examples.json5 | 9 ----- examples/29-effect-in-handler/shed.json5 | 8 ---- examples/29-effect-in-handler/src/Example.shed | 44 ---------------------- examples/30-effect-break/shed-examples.json5 | 9 ----- examples/30-effect-break/shed.json5 | 8 ---- examples/30-effect-break/src/HelloWorld.shed | 27 ------------- examples/30-effect-in-handler/shed-examples.json5 | 9 +++++ examples/30-effect-in-handler/shed.json5 | 8 ++++ examples/30-effect-in-handler/src/Example.shed | 44 ++++++++++++++++++++++ examples/31-effect-break/shed-examples.json5 | 9 +++++ examples/31-effect-break/shed.json5 | 8 ++++ examples/31-effect-break/src/HelloWorld.shed | 27 +++++++++++++ examples/31-generic-structs/shed-examples.json5 | 9 ----- examples/31-generic-structs/shed.json5 | 8 ---- examples/31-generic-structs/src/HelloWorld.shed | 15 -------- examples/32-generic-structs/shed-examples.json5 | 9 +++++ examples/32-generic-structs/shed.json5 | 8 ++++ examples/32-generic-structs/src/HelloWorld.shed | 15 ++++++++ examples/32-generic-sums/shed-examples.json5 | 9 ----- examples/32-generic-sums/shed.json5 | 8 ---- examples/32-generic-sums/src/HelloWorld.shed | 23 ----------- .../shed-examples.json5 | 9 ----- .../shed.json5 | 8 ---- .../src/HelloWorld.shed | 23 ----------- examples/33-generic-sums/shed-examples.json5 | 9 +++++ examples/33-generic-sums/shed.json5 | 8 ++++ examples/33-generic-sums/src/HelloWorld.shed | 23 +++++++++++ examples/34-generic-functions/shed-examples.json5 | 9 ----- examples/34-generic-functions/shed.json5 | 8 ---- examples/34-generic-functions/src/HelloWorld.shed | 15 -------- .../shed-examples.json5 | 9 +++++ .../shed.json5 | 8 ++++ .../src/HelloWorld.shed | 23 +++++++++++ examples/35-generic-effects/shed-examples.json5 | 9 ----- examples/35-generic-effects/shed.json5 | 8 ---- examples/35-generic-effects/src/HelloWorld.shed | 11 ------ examples/35-generic-functions/shed-examples.json5 | 9 +++++ examples/35-generic-functions/shed.json5 | 8 ++++ examples/35-generic-functions/src/HelloWorld.shed | 15 ++++++++ examples/36-generic-effects/shed-examples.json5 | 9 +++++ examples/36-generic-effects/shed.json5 | 8 ++++ examples/36-generic-effects/src/HelloWorld.shed | 11 ++++++ examples/36-struct-methods/shed-examples.json5 | 9 ----- examples/36-struct-methods/shed.json5 | 8 ---- examples/36-struct-methods/src/HelloWorld.shed | 17 --------- .../shed-examples.json5 | 9 ----- examples/37-struct-method-references/shed.json5 | 8 ---- .../src/HelloWorld.shed | 25 ------------ examples/37-struct-methods/shed-examples.json5 | 9 +++++ examples/37-struct-methods/shed.json5 | 8 ++++ examples/37-struct-methods/src/HelloWorld.shed | 17 +++++++++ .../38-generic-struct-methods/shed-examples.json5 | 9 ----- examples/38-generic-struct-methods/shed.json5 | 8 ---- .../38-generic-struct-methods/src/HelloWorld.shed | 11 ------ .../shed-examples.json5 | 9 +++++ examples/38-struct-method-references/shed.json5 | 8 ++++ .../src/HelloWorld.shed | 25 ++++++++++++ .../39-generic-struct-methods/shed-examples.json5 | 9 +++++ examples/39-generic-struct-methods/shed.json5 | 8 ++++ .../39-generic-struct-methods/src/HelloWorld.shed | 11 ++++++ 122 files changed, 783 insertions(+), 742 deletions(-) delete mode 100644 examples/20-function-expression/shed-examples.json5 delete mode 100644 examples/20-function-expression/shed.json5 delete mode 100644 examples/20-function-expression/src/HelloWorld.shed create mode 100644 examples/20-import-recursive-dependency/hello-world/.gitignore create mode 100644 examples/20-import-recursive-dependency/hello-world/shed.json5 create mode 100644 examples/20-import-recursive-dependency/hello-world/src/HelloWorld.shed create mode 100644 examples/20-import-recursive-dependency/message1/shed.json5 create mode 100644 examples/20-import-recursive-dependency/message1/src/Message1.shed create mode 100644 examples/20-import-recursive-dependency/message2/shed.json5 create mode 100644 examples/20-import-recursive-dependency/message2/src/Message2.shed create mode 100644 examples/20-import-recursive-dependency/shed-examples.json5 delete mode 100644 examples/21-function-expression-infer-return-type/shed-examples.json5 delete mode 100644 examples/21-function-expression-infer-return-type/shed.json5 delete mode 100644 examples/21-function-expression-infer-return-type/src/HelloWorld.shed create mode 100644 examples/21-function-expression/shed-examples.json5 create mode 100644 examples/21-function-expression/shed.json5 create mode 100644 examples/21-function-expression/src/HelloWorld.shed delete mode 100644 examples/22-function-expression-infer-param-type/shed-examples.json5 delete mode 100644 examples/22-function-expression-infer-param-type/shed.json5 delete mode 100644 examples/22-function-expression-infer-param-type/src/HelloWorld.shed create mode 100644 examples/22-function-expression-infer-return-type/shed-examples.json5 create mode 100644 examples/22-function-expression-infer-return-type/shed.json5 create mode 100644 examples/22-function-expression-infer-return-type/src/HelloWorld.shed delete mode 100644 examples/23-effect-resume/shed-examples.json5 delete mode 100644 examples/23-effect-resume/shed.json5 delete mode 100644 examples/23-effect-resume/src/HelloWorld.shed create mode 100644 examples/23-function-expression-infer-param-type/shed-examples.json5 create mode 100644 examples/23-function-expression-infer-param-type/shed.json5 create mode 100644 examples/23-function-expression-infer-param-type/src/HelloWorld.shed delete mode 100644 examples/24-effect-resume-with-value/shed-examples.json5 delete mode 100644 examples/24-effect-resume-with-value/shed.json5 delete mode 100644 examples/24-effect-resume-with-value/src/HelloWorld.shed create mode 100644 examples/24-effect-resume/shed-examples.json5 create mode 100644 examples/24-effect-resume/shed.json5 create mode 100644 examples/24-effect-resume/src/HelloWorld.shed create mode 100644 examples/25-effect-resume-with-value/shed-examples.json5 create mode 100644 examples/25-effect-resume-with-value/shed.json5 create mode 100644 examples/25-effect-resume-with-value/src/HelloWorld.shed delete mode 100644 examples/25-effect-with-state/shed-examples.json5 delete mode 100644 examples/25-effect-with-state/shed.json5 delete mode 100644 examples/25-effect-with-state/src/HelloWorld.shed delete mode 100644 examples/26-effect-handler-pop/shed-examples.json5 delete mode 100644 examples/26-effect-handler-pop/shed.json5 delete mode 100644 examples/26-effect-handler-pop/src/HelloWorld.shed create mode 100644 examples/26-effect-with-state/shed-examples.json5 create mode 100644 examples/26-effect-with-state/shed.json5 create mode 100644 examples/26-effect-with-state/src/HelloWorld.shed delete mode 100644 examples/27-effect-handler-pop-on-return/shed-examples.json5 delete mode 100644 examples/27-effect-handler-pop-on-return/shed.json5 delete mode 100644 examples/27-effect-handler-pop-on-return/src/HelloWorld.shed create mode 100644 examples/27-effect-handler-pop/shed-examples.json5 create mode 100644 examples/27-effect-handler-pop/shed.json5 create mode 100644 examples/27-effect-handler-pop/src/HelloWorld.shed delete mode 100644 examples/28-effect-handler-nested/shed-examples.json5 delete mode 100644 examples/28-effect-handler-nested/shed.json5 delete mode 100644 examples/28-effect-handler-nested/src/Example.shed create mode 100644 examples/28-effect-handler-pop-on-return/shed-examples.json5 create mode 100644 examples/28-effect-handler-pop-on-return/shed.json5 create mode 100644 examples/28-effect-handler-pop-on-return/src/HelloWorld.shed create mode 100644 examples/29-effect-handler-nested/shed-examples.json5 create mode 100644 examples/29-effect-handler-nested/shed.json5 create mode 100644 examples/29-effect-handler-nested/src/Example.shed delete mode 100644 examples/29-effect-in-handler/shed-examples.json5 delete mode 100644 examples/29-effect-in-handler/shed.json5 delete mode 100644 examples/29-effect-in-handler/src/Example.shed delete mode 100644 examples/30-effect-break/shed-examples.json5 delete mode 100644 examples/30-effect-break/shed.json5 delete mode 100644 examples/30-effect-break/src/HelloWorld.shed create mode 100644 examples/30-effect-in-handler/shed-examples.json5 create mode 100644 examples/30-effect-in-handler/shed.json5 create mode 100644 examples/30-effect-in-handler/src/Example.shed create mode 100644 examples/31-effect-break/shed-examples.json5 create mode 100644 examples/31-effect-break/shed.json5 create mode 100644 examples/31-effect-break/src/HelloWorld.shed delete mode 100644 examples/31-generic-structs/shed-examples.json5 delete mode 100644 examples/31-generic-structs/shed.json5 delete mode 100644 examples/31-generic-structs/src/HelloWorld.shed create mode 100644 examples/32-generic-structs/shed-examples.json5 create mode 100644 examples/32-generic-structs/shed.json5 create mode 100644 examples/32-generic-structs/src/HelloWorld.shed delete mode 100644 examples/32-generic-sums/shed-examples.json5 delete mode 100644 examples/32-generic-sums/shed.json5 delete mode 100644 examples/32-generic-sums/src/HelloWorld.shed delete mode 100644 examples/33-generic-structs-and-sums-inferred-type-args/shed-examples.json5 delete mode 100644 examples/33-generic-structs-and-sums-inferred-type-args/shed.json5 delete mode 100644 examples/33-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed create mode 100644 examples/33-generic-sums/shed-examples.json5 create mode 100644 examples/33-generic-sums/shed.json5 create mode 100644 examples/33-generic-sums/src/HelloWorld.shed delete mode 100644 examples/34-generic-functions/shed-examples.json5 delete mode 100644 examples/34-generic-functions/shed.json5 delete mode 100644 examples/34-generic-functions/src/HelloWorld.shed create mode 100644 examples/34-generic-structs-and-sums-inferred-type-args/shed-examples.json5 create mode 100644 examples/34-generic-structs-and-sums-inferred-type-args/shed.json5 create mode 100644 examples/34-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed delete mode 100644 examples/35-generic-effects/shed-examples.json5 delete mode 100644 examples/35-generic-effects/shed.json5 delete mode 100644 examples/35-generic-effects/src/HelloWorld.shed create mode 100644 examples/35-generic-functions/shed-examples.json5 create mode 100644 examples/35-generic-functions/shed.json5 create mode 100644 examples/35-generic-functions/src/HelloWorld.shed create mode 100644 examples/36-generic-effects/shed-examples.json5 create mode 100644 examples/36-generic-effects/shed.json5 create mode 100644 examples/36-generic-effects/src/HelloWorld.shed delete mode 100644 examples/36-struct-methods/shed-examples.json5 delete mode 100644 examples/36-struct-methods/shed.json5 delete mode 100644 examples/36-struct-methods/src/HelloWorld.shed delete mode 100644 examples/37-struct-method-references/shed-examples.json5 delete mode 100644 examples/37-struct-method-references/shed.json5 delete mode 100644 examples/37-struct-method-references/src/HelloWorld.shed create mode 100644 examples/37-struct-methods/shed-examples.json5 create mode 100644 examples/37-struct-methods/shed.json5 create mode 100644 examples/37-struct-methods/src/HelloWorld.shed delete mode 100644 examples/38-generic-struct-methods/shed-examples.json5 delete mode 100644 examples/38-generic-struct-methods/shed.json5 delete mode 100644 examples/38-generic-struct-methods/src/HelloWorld.shed create mode 100644 examples/38-struct-method-references/shed-examples.json5 create mode 100644 examples/38-struct-method-references/shed.json5 create mode 100644 examples/38-struct-method-references/src/HelloWorld.shed create mode 100644 examples/39-generic-struct-methods/shed-examples.json5 create mode 100644 examples/39-generic-struct-methods/shed.json5 create mode 100644 examples/39-generic-struct-methods/src/HelloWorld.shed (limited to 'examples') diff --git a/examples/20-function-expression/shed-examples.json5 b/examples/20-function-expression/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/20-function-expression/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/20-function-expression/shed.json5 b/examples/20-function-expression/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/20-function-expression/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/20-function-expression/src/HelloWorld.shed b/examples/20-function-expression/src/HelloWorld.shed deleted file mode 100644 index 1ebb2863..00000000 --- a/examples/20-function-expression/src/HelloWorld.shed +++ /dev/null @@ -1,11 +0,0 @@ -fun printer(left: String) -> fn (String) ! Io -> Unit { - fn (right: String) !Io -> Unit { - print!(left); - print!(right); - } -} - -pub fun main() ! Io -> Unit { - printer("hello")!(", "); - printer("world")!("\n"); -} diff --git a/examples/20-import-recursive-dependency/hello-world/.gitignore b/examples/20-import-recursive-dependency/hello-world/.gitignore new file mode 100644 index 00000000..ea8c4bf7 --- /dev/null +++ b/examples/20-import-recursive-dependency/hello-world/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/20-import-recursive-dependency/hello-world/shed.json5 b/examples/20-import-recursive-dependency/hello-world/shed.json5 new file mode 100644 index 00000000..fad540d8 --- /dev/null +++ b/examples/20-import-recursive-dependency/hello-world/shed.json5 @@ -0,0 +1,13 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], + dependencies: [ + { + path: "../message1" + } + ], +} diff --git a/examples/20-import-recursive-dependency/hello-world/src/HelloWorld.shed b/examples/20-import-recursive-dependency/hello-world/src/HelloWorld.shed new file mode 100644 index 00000000..f63849d4 --- /dev/null +++ b/examples/20-import-recursive-dependency/hello-world/src/HelloWorld.shed @@ -0,0 +1,5 @@ +import Message1; + +pub fun main() ! Io -> Unit { + print!(Message1.message); +} diff --git a/examples/20-import-recursive-dependency/message1/shed.json5 b/examples/20-import-recursive-dependency/message1/shed.json5 new file mode 100644 index 00000000..1faaf200 --- /dev/null +++ b/examples/20-import-recursive-dependency/message1/shed.json5 @@ -0,0 +1,7 @@ +{ + dependencies: [ + { + path: "../message2" + } + ] +} diff --git a/examples/20-import-recursive-dependency/message1/src/Message1.shed b/examples/20-import-recursive-dependency/message1/src/Message1.shed new file mode 100644 index 00000000..aa497683 --- /dev/null +++ b/examples/20-import-recursive-dependency/message1/src/Message1.shed @@ -0,0 +1,3 @@ +import Message2; + +pub val message = Message2.message; diff --git a/examples/20-import-recursive-dependency/message2/shed.json5 b/examples/20-import-recursive-dependency/message2/shed.json5 new file mode 100644 index 00000000..2c63c085 --- /dev/null +++ b/examples/20-import-recursive-dependency/message2/shed.json5 @@ -0,0 +1,2 @@ +{ +} diff --git a/examples/20-import-recursive-dependency/message2/src/Message2.shed b/examples/20-import-recursive-dependency/message2/src/Message2.shed new file mode 100644 index 00000000..db03110a --- /dev/null +++ b/examples/20-import-recursive-dependency/message2/src/Message2.shed @@ -0,0 +1 @@ +pub val message = "hello, world\n"; diff --git a/examples/20-import-recursive-dependency/shed-examples.json5 b/examples/20-import-recursive-dependency/shed-examples.json5 new file mode 100644 index 00000000..64a897eb --- /dev/null +++ b/examples/20-import-recursive-dependency/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: "./hello-world", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/21-function-expression-infer-return-type/shed-examples.json5 b/examples/21-function-expression-infer-return-type/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/21-function-expression-infer-return-type/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/21-function-expression-infer-return-type/shed.json5 b/examples/21-function-expression-infer-return-type/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/21-function-expression-infer-return-type/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/21-function-expression-infer-return-type/src/HelloWorld.shed b/examples/21-function-expression-infer-return-type/src/HelloWorld.shed deleted file mode 100644 index 1c93c946..00000000 --- a/examples/21-function-expression-infer-return-type/src/HelloWorld.shed +++ /dev/null @@ -1,4 +0,0 @@ -pub fun main() ! Io -> Unit { - val message = fn () { "hello, world\n" }; - print!(message()); -} diff --git a/examples/21-function-expression/shed-examples.json5 b/examples/21-function-expression/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/21-function-expression/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/21-function-expression/shed.json5 b/examples/21-function-expression/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/21-function-expression/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/21-function-expression/src/HelloWorld.shed b/examples/21-function-expression/src/HelloWorld.shed new file mode 100644 index 00000000..1ebb2863 --- /dev/null +++ b/examples/21-function-expression/src/HelloWorld.shed @@ -0,0 +1,11 @@ +fun printer(left: String) -> fn (String) ! Io -> Unit { + fn (right: String) !Io -> Unit { + print!(left); + print!(right); + } +} + +pub fun main() ! Io -> Unit { + printer("hello")!(", "); + printer("world")!("\n"); +} diff --git a/examples/22-function-expression-infer-param-type/shed-examples.json5 b/examples/22-function-expression-infer-param-type/shed-examples.json5 deleted file mode 100644 index 81fa6d68..00000000 --- a/examples/22-function-expression-infer-param-type/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world\nworld, hello", - }, - ], -} diff --git a/examples/22-function-expression-infer-param-type/shed.json5 b/examples/22-function-expression-infer-param-type/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/22-function-expression-infer-param-type/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/22-function-expression-infer-param-type/src/HelloWorld.shed b/examples/22-function-expression-infer-param-type/src/HelloWorld.shed deleted file mode 100644 index e91bc5e0..00000000 --- a/examples/22-function-expression-infer-param-type/src/HelloWorld.shed +++ /dev/null @@ -1,8 +0,0 @@ -pub fun main() ! Io -> Unit { - printHelloWorld!(fn (left, right) { left + ", " + right + "\n" }); - printHelloWorld!(fn (left, right) { right + ", " + left + "\n" }) -} - -fun printHelloWorld(combine: fn (String, String) -> String) !Io -> Unit { - print!(combine("hello", "world")); -} diff --git a/examples/22-function-expression-infer-return-type/shed-examples.json5 b/examples/22-function-expression-infer-return-type/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/22-function-expression-infer-return-type/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/22-function-expression-infer-return-type/shed.json5 b/examples/22-function-expression-infer-return-type/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/22-function-expression-infer-return-type/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/22-function-expression-infer-return-type/src/HelloWorld.shed b/examples/22-function-expression-infer-return-type/src/HelloWorld.shed new file mode 100644 index 00000000..1c93c946 --- /dev/null +++ b/examples/22-function-expression-infer-return-type/src/HelloWorld.shed @@ -0,0 +1,4 @@ +pub fun main() ! Io -> Unit { + val message = fn () { "hello, world\n" }; + print!(message()); +} diff --git a/examples/23-effect-resume/shed-examples.json5 b/examples/23-effect-resume/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/23-effect-resume/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/23-effect-resume/shed.json5 b/examples/23-effect-resume/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/23-effect-resume/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/23-effect-resume/src/HelloWorld.shed b/examples/23-effect-resume/src/HelloWorld.shed deleted file mode 100644 index a5e96e2f..00000000 --- a/examples/23-effect-resume/src/HelloWorld.shed +++ /dev/null @@ -1,23 +0,0 @@ -effect Writer { - fun hello() -> Unit; - fun world() -> Unit; -} - -pub fun main() ! Io -> Unit { - try { - Writer.hello!(); - print!(", "); - Writer.world!(); - print!("\n"); - } handle Writer { - fun hello() { - print!("hello"); - resume; - } - - fun world() { - print!("world"); - resume; - } - } -} diff --git a/examples/23-function-expression-infer-param-type/shed-examples.json5 b/examples/23-function-expression-infer-param-type/shed-examples.json5 new file mode 100644 index 00000000..81fa6d68 --- /dev/null +++ b/examples/23-function-expression-infer-param-type/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world\nworld, hello", + }, + ], +} diff --git a/examples/23-function-expression-infer-param-type/shed.json5 b/examples/23-function-expression-infer-param-type/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/23-function-expression-infer-param-type/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/23-function-expression-infer-param-type/src/HelloWorld.shed b/examples/23-function-expression-infer-param-type/src/HelloWorld.shed new file mode 100644 index 00000000..e91bc5e0 --- /dev/null +++ b/examples/23-function-expression-infer-param-type/src/HelloWorld.shed @@ -0,0 +1,8 @@ +pub fun main() ! Io -> Unit { + printHelloWorld!(fn (left, right) { left + ", " + right + "\n" }); + printHelloWorld!(fn (left, right) { right + ", " + left + "\n" }) +} + +fun printHelloWorld(combine: fn (String, String) -> String) !Io -> Unit { + print!(combine("hello", "world")); +} diff --git a/examples/24-effect-resume-with-value/shed-examples.json5 b/examples/24-effect-resume-with-value/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/24-effect-resume-with-value/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/24-effect-resume-with-value/shed.json5 b/examples/24-effect-resume-with-value/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/24-effect-resume-with-value/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/24-effect-resume-with-value/src/HelloWorld.shed b/examples/24-effect-resume-with-value/src/HelloWorld.shed deleted file mode 100644 index 3252aaf3..00000000 --- a/examples/24-effect-resume-with-value/src/HelloWorld.shed +++ /dev/null @@ -1,21 +0,0 @@ -effect Messages { - fun hello() -> String; - fun world() -> String; -} - -pub fun main() ! Io -> Unit { - try { - print!(Messages.hello!()); - print!(", "); - print!(Messages.world!()); - print!("\n"); - } handle Messages { - fun hello() { - resume "hello"; - } - - fun world() { - resume "world"; - } - } -} diff --git a/examples/24-effect-resume/shed-examples.json5 b/examples/24-effect-resume/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/24-effect-resume/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/24-effect-resume/shed.json5 b/examples/24-effect-resume/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/24-effect-resume/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/24-effect-resume/src/HelloWorld.shed b/examples/24-effect-resume/src/HelloWorld.shed new file mode 100644 index 00000000..a5e96e2f --- /dev/null +++ b/examples/24-effect-resume/src/HelloWorld.shed @@ -0,0 +1,23 @@ +effect Writer { + fun hello() -> Unit; + fun world() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + Writer.hello!(); + print!(", "); + Writer.world!(); + print!("\n"); + } handle Writer { + fun hello() { + print!("hello"); + resume; + } + + fun world() { + print!("world"); + resume; + } + } +} diff --git a/examples/25-effect-resume-with-value/shed-examples.json5 b/examples/25-effect-resume-with-value/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/25-effect-resume-with-value/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/25-effect-resume-with-value/shed.json5 b/examples/25-effect-resume-with-value/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/25-effect-resume-with-value/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/25-effect-resume-with-value/src/HelloWorld.shed b/examples/25-effect-resume-with-value/src/HelloWorld.shed new file mode 100644 index 00000000..3252aaf3 --- /dev/null +++ b/examples/25-effect-resume-with-value/src/HelloWorld.shed @@ -0,0 +1,21 @@ +effect Messages { + fun hello() -> String; + fun world() -> String; +} + +pub fun main() ! Io -> Unit { + try { + print!(Messages.hello!()); + print!(", "); + print!(Messages.world!()); + print!("\n"); + } handle Messages { + fun hello() { + resume "hello"; + } + + fun world() { + resume "world"; + } + } +} diff --git a/examples/25-effect-with-state/shed-examples.json5 b/examples/25-effect-with-state/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/25-effect-with-state/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/25-effect-with-state/shed.json5 b/examples/25-effect-with-state/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/25-effect-with-state/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/25-effect-with-state/src/HelloWorld.shed b/examples/25-effect-with-state/src/HelloWorld.shed deleted file mode 100644 index 50d64428..00000000 --- a/examples/25-effect-with-state/src/HelloWorld.shed +++ /dev/null @@ -1,22 +0,0 @@ -effect StringBuilder { - fun append(String) -> Unit; -} - -pub fun main() ! Io -> Unit { - var result = ""; - - try { - StringBuilder.append!("hello"); - StringBuilder.append!(", "); - StringBuilder.append!("world"); - StringBuilder.append!("\n"); - } handle StringBuilder { - fun append(value) { - assign result = result + value; - - resume; - } - } - - print!(result); -} diff --git a/examples/26-effect-handler-pop/shed-examples.json5 b/examples/26-effect-handler-pop/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/26-effect-handler-pop/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/26-effect-handler-pop/shed.json5 b/examples/26-effect-handler-pop/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/26-effect-handler-pop/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/26-effect-handler-pop/src/HelloWorld.shed b/examples/26-effect-handler-pop/src/HelloWorld.shed deleted file mode 100644 index 2b9491d7..00000000 --- a/examples/26-effect-handler-pop/src/HelloWorld.shed +++ /dev/null @@ -1,36 +0,0 @@ -effect Writer { - fun hello() -> Unit; - fun world() -> Unit; -} - -pub fun main() ! Io -> Unit { - try { - Writer.hello!(); - print!(", "); - } handle Writer { - fun hello() { - print!("hello"); - resume; - } - - fun world() { - print!("world"); - resume; - } - } - - try { - Writer.world!(); - print!("\n"); - } handle Writer { - fun hello() { - print!("hello"); - resume; - } - - fun world() { - print!("world"); - resume; - } - } -} diff --git a/examples/26-effect-with-state/shed-examples.json5 b/examples/26-effect-with-state/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/26-effect-with-state/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/26-effect-with-state/shed.json5 b/examples/26-effect-with-state/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/26-effect-with-state/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/26-effect-with-state/src/HelloWorld.shed b/examples/26-effect-with-state/src/HelloWorld.shed new file mode 100644 index 00000000..50d64428 --- /dev/null +++ b/examples/26-effect-with-state/src/HelloWorld.shed @@ -0,0 +1,22 @@ +effect StringBuilder { + fun append(String) -> Unit; +} + +pub fun main() ! Io -> Unit { + var result = ""; + + try { + StringBuilder.append!("hello"); + StringBuilder.append!(", "); + StringBuilder.append!("world"); + StringBuilder.append!("\n"); + } handle StringBuilder { + fun append(value) { + assign result = result + value; + + resume; + } + } + + print!(result); +} diff --git a/examples/27-effect-handler-pop-on-return/shed-examples.json5 b/examples/27-effect-handler-pop-on-return/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/27-effect-handler-pop-on-return/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/27-effect-handler-pop-on-return/shed.json5 b/examples/27-effect-handler-pop-on-return/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/27-effect-handler-pop-on-return/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/27-effect-handler-pop-on-return/src/HelloWorld.shed b/examples/27-effect-handler-pop-on-return/src/HelloWorld.shed deleted file mode 100644 index 4e91f8b4..00000000 --- a/examples/27-effect-handler-pop-on-return/src/HelloWorld.shed +++ /dev/null @@ -1,41 +0,0 @@ -effect Writer { - fun hello() -> Unit; - fun world() -> Unit; -} - -pub fun main() ! Io -> Unit { - try { - hello!(); - Writer.world!(); - print!("\n"); - return; - } handle Writer { - fun hello() { - print!("wrong hello"); - resume; - } - - fun world() { - print!("world"); - resume; - } - } -} - -fun hello() ! Io -> Unit { - try { - Writer.hello!(); - print!(", "); - return; - } handle Writer { - fun hello() { - print!("hello"); - resume; - } - - fun world() { - print!("wrong world"); - resume; - } - } -} diff --git a/examples/27-effect-handler-pop/shed-examples.json5 b/examples/27-effect-handler-pop/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/27-effect-handler-pop/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/27-effect-handler-pop/shed.json5 b/examples/27-effect-handler-pop/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/27-effect-handler-pop/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/27-effect-handler-pop/src/HelloWorld.shed b/examples/27-effect-handler-pop/src/HelloWorld.shed new file mode 100644 index 00000000..2b9491d7 --- /dev/null +++ b/examples/27-effect-handler-pop/src/HelloWorld.shed @@ -0,0 +1,36 @@ +effect Writer { + fun hello() -> Unit; + fun world() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + Writer.hello!(); + print!(", "); + } handle Writer { + fun hello() { + print!("hello"); + resume; + } + + fun world() { + print!("world"); + resume; + } + } + + try { + Writer.world!(); + print!("\n"); + } handle Writer { + fun hello() { + print!("hello"); + resume; + } + + fun world() { + print!("world"); + resume; + } + } +} diff --git a/examples/28-effect-handler-nested/shed-examples.json5 b/examples/28-effect-handler-nested/shed-examples.json5 deleted file mode 100644 index 13ea0b50..00000000 --- a/examples/28-effect-handler-nested/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "example", - expectedOutput: "a outer\na inner\na inner\nb\na inner\na inner\na outer", - }, - ], -} diff --git a/examples/28-effect-handler-nested/shed.json5 b/examples/28-effect-handler-nested/shed.json5 deleted file mode 100644 index e642a813..00000000 --- a/examples/28-effect-handler-nested/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "example", - mainNamespace: "Example", - }, - ], -} diff --git a/examples/28-effect-handler-nested/src/Example.shed b/examples/28-effect-handler-nested/src/Example.shed deleted file mode 100644 index 2a8e4781..00000000 --- a/examples/28-effect-handler-nested/src/Example.shed +++ /dev/null @@ -1,42 +0,0 @@ -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; - } - } -} diff --git a/examples/28-effect-handler-pop-on-return/shed-examples.json5 b/examples/28-effect-handler-pop-on-return/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/28-effect-handler-pop-on-return/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/28-effect-handler-pop-on-return/shed.json5 b/examples/28-effect-handler-pop-on-return/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/28-effect-handler-pop-on-return/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/28-effect-handler-pop-on-return/src/HelloWorld.shed b/examples/28-effect-handler-pop-on-return/src/HelloWorld.shed new file mode 100644 index 00000000..4e91f8b4 --- /dev/null +++ b/examples/28-effect-handler-pop-on-return/src/HelloWorld.shed @@ -0,0 +1,41 @@ +effect Writer { + fun hello() -> Unit; + fun world() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + hello!(); + Writer.world!(); + print!("\n"); + return; + } handle Writer { + fun hello() { + print!("wrong hello"); + resume; + } + + fun world() { + print!("world"); + resume; + } + } +} + +fun hello() ! Io -> Unit { + try { + Writer.hello!(); + print!(", "); + return; + } handle Writer { + fun hello() { + print!("hello"); + resume; + } + + fun world() { + print!("wrong world"); + resume; + } + } +} diff --git a/examples/29-effect-handler-nested/shed-examples.json5 b/examples/29-effect-handler-nested/shed-examples.json5 new file mode 100644 index 00000000..13ea0b50 --- /dev/null +++ b/examples/29-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/29-effect-handler-nested/shed.json5 b/examples/29-effect-handler-nested/shed.json5 new file mode 100644 index 00000000..e642a813 --- /dev/null +++ b/examples/29-effect-handler-nested/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "example", + mainNamespace: "Example", + }, + ], +} diff --git a/examples/29-effect-handler-nested/src/Example.shed b/examples/29-effect-handler-nested/src/Example.shed new file mode 100644 index 00000000..2a8e4781 --- /dev/null +++ b/examples/29-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; + } + } +} diff --git a/examples/29-effect-in-handler/shed-examples.json5 b/examples/29-effect-in-handler/shed-examples.json5 deleted file mode 100644 index 0717d99b..00000000 --- a/examples/29-effect-in-handler/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "example", - expectedOutput: "a outer\na inner start\na outer\na inner end\nb start\na inner start\na outer\na inner end\nb end\na inner start\na outer\na inner end\na outer", - }, - ], -} diff --git a/examples/29-effect-in-handler/shed.json5 b/examples/29-effect-in-handler/shed.json5 deleted file mode 100644 index e642a813..00000000 --- a/examples/29-effect-in-handler/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "example", - mainNamespace: "Example", - }, - ], -} diff --git a/examples/29-effect-in-handler/src/Example.shed b/examples/29-effect-in-handler/src/Example.shed deleted file mode 100644 index 568d9ea8..00000000 --- a/examples/29-effect-in-handler/src/Example.shed +++ /dev/null @@ -1,44 +0,0 @@ -effect A { - fun a() -> Unit; -} - -effect B { - fun b() -> Unit; -} - -pub fun main() ! Io -> Unit { - try { - A.a!(); - - try { - A.a!(); - - try { - B.b!(); - } handle B { - fun b() { - print!("b start\n"); - A.a!(); - print!("b end\n"); - resume; - } - } - - A.a!(); - } handle A { - fun a() { - print!("a inner start\n"); - A.a!(); - print!("a inner end\n"); - resume; - } - } - - A.a!(); - } handle A { - fun a() { - print!("a outer\n"); - resume; - } - } -} diff --git a/examples/30-effect-break/shed-examples.json5 b/examples/30-effect-break/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/30-effect-break/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/30-effect-break/shed.json5 b/examples/30-effect-break/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/30-effect-break/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/30-effect-break/src/HelloWorld.shed b/examples/30-effect-break/src/HelloWorld.shed deleted file mode 100644 index f836ab58..00000000 --- a/examples/30-effect-break/src/HelloWorld.shed +++ /dev/null @@ -1,27 +0,0 @@ -effect Writer { - fun hello() -> Unit; - fun world() -> Unit; -} - -pub fun main() ! Io -> Unit { - try { - Writer.hello!(); - print!(", "); - Writer.world!(); - Writer.hello!(); - print!(", "); - Writer.world!(); - } handle Writer { - fun hello() { - print!("hello"); - resume; - } - - fun world() { - print!("world"); - break; - } - } - - print!("\n"); -} diff --git a/examples/30-effect-in-handler/shed-examples.json5 b/examples/30-effect-in-handler/shed-examples.json5 new file mode 100644 index 00000000..0717d99b --- /dev/null +++ b/examples/30-effect-in-handler/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "example", + expectedOutput: "a outer\na inner start\na outer\na inner end\nb start\na inner start\na outer\na inner end\nb end\na inner start\na outer\na inner end\na outer", + }, + ], +} diff --git a/examples/30-effect-in-handler/shed.json5 b/examples/30-effect-in-handler/shed.json5 new file mode 100644 index 00000000..e642a813 --- /dev/null +++ b/examples/30-effect-in-handler/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "example", + mainNamespace: "Example", + }, + ], +} diff --git a/examples/30-effect-in-handler/src/Example.shed b/examples/30-effect-in-handler/src/Example.shed new file mode 100644 index 00000000..568d9ea8 --- /dev/null +++ b/examples/30-effect-in-handler/src/Example.shed @@ -0,0 +1,44 @@ +effect A { + fun a() -> Unit; +} + +effect B { + fun b() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + A.a!(); + + try { + A.a!(); + + try { + B.b!(); + } handle B { + fun b() { + print!("b start\n"); + A.a!(); + print!("b end\n"); + resume; + } + } + + A.a!(); + } handle A { + fun a() { + print!("a inner start\n"); + A.a!(); + print!("a inner end\n"); + resume; + } + } + + A.a!(); + } handle A { + fun a() { + print!("a outer\n"); + resume; + } + } +} diff --git a/examples/31-effect-break/shed-examples.json5 b/examples/31-effect-break/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/31-effect-break/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/31-effect-break/shed.json5 b/examples/31-effect-break/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/31-effect-break/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/31-effect-break/src/HelloWorld.shed b/examples/31-effect-break/src/HelloWorld.shed new file mode 100644 index 00000000..f836ab58 --- /dev/null +++ b/examples/31-effect-break/src/HelloWorld.shed @@ -0,0 +1,27 @@ +effect Writer { + fun hello() -> Unit; + fun world() -> Unit; +} + +pub fun main() ! Io -> Unit { + try { + Writer.hello!(); + print!(", "); + Writer.world!(); + Writer.hello!(); + print!(", "); + Writer.world!(); + } handle Writer { + fun hello() { + print!("hello"); + resume; + } + + fun world() { + print!("world"); + break; + } + } + + print!("\n"); +} diff --git a/examples/31-generic-structs/shed-examples.json5 b/examples/31-generic-structs/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/31-generic-structs/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/31-generic-structs/shed.json5 b/examples/31-generic-structs/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/31-generic-structs/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/31-generic-structs/src/HelloWorld.shed b/examples/31-generic-structs/src/HelloWorld.shed deleted file mode 100644 index f5a2f013..00000000 --- a/examples/31-generic-structs/src/HelloWorld.shed +++ /dev/null @@ -1,15 +0,0 @@ -pub fun main() ! Io -> Unit { - val messageParts = getMessageParts(); - print!(messageParts.part1); - print!(messageParts.part2); -} - -struct Parts[T1, T2]( - .part1: T1, - .part2: T2, -) { -} - -fun getMessageParts() -> Parts[String, String] { - Parts[String, String](.part1 = "hello, ", .part2 = "world\n") -} diff --git a/examples/32-generic-structs/shed-examples.json5 b/examples/32-generic-structs/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/32-generic-structs/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/32-generic-structs/shed.json5 b/examples/32-generic-structs/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/32-generic-structs/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/32-generic-structs/src/HelloWorld.shed b/examples/32-generic-structs/src/HelloWorld.shed new file mode 100644 index 00000000..f5a2f013 --- /dev/null +++ b/examples/32-generic-structs/src/HelloWorld.shed @@ -0,0 +1,15 @@ +pub fun main() ! Io -> Unit { + val messageParts = getMessageParts(); + print!(messageParts.part1); + print!(messageParts.part2); +} + +struct Parts[T1, T2]( + .part1: T1, + .part2: T2, +) { +} + +fun getMessageParts() -> Parts[String, String] { + Parts[String, String](.part1 = "hello, ", .part2 = "world\n") +} diff --git a/examples/32-generic-sums/shed-examples.json5 b/examples/32-generic-sums/shed-examples.json5 deleted file mode 100644 index 4a4b2b7c..00000000 --- a/examples/32-generic-sums/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "Some(hello, world!)\nNone", - }, - ], -} diff --git a/examples/32-generic-sums/shed.json5 b/examples/32-generic-sums/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/32-generic-sums/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/32-generic-sums/src/HelloWorld.shed b/examples/32-generic-sums/src/HelloWorld.shed deleted file mode 100644 index e10456bd..00000000 --- a/examples/32-generic-sums/src/HelloWorld.shed +++ /dev/null @@ -1,23 +0,0 @@ -struct Some[T](value: T) {} - -struct None() {} - -sumtype Option[T] = Some[T] | None; - -pub fun main() ! Io -> Unit { - printOption!(Some[String]("hello, world!")); - printOption!(None()); -} - -fun printOption(option: Option[String]) !Io -> Unit { - when (option) { - is Some[String] { - print!("Some("); - print!(option.value); - print!(")\n"); - } - is None { - print!("None\n"); - } - } -} diff --git a/examples/33-generic-structs-and-sums-inferred-type-args/shed-examples.json5 b/examples/33-generic-structs-and-sums-inferred-type-args/shed-examples.json5 deleted file mode 100644 index 4a4b2b7c..00000000 --- a/examples/33-generic-structs-and-sums-inferred-type-args/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "Some(hello, world!)\nNone", - }, - ], -} diff --git a/examples/33-generic-structs-and-sums-inferred-type-args/shed.json5 b/examples/33-generic-structs-and-sums-inferred-type-args/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/33-generic-structs-and-sums-inferred-type-args/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/33-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed b/examples/33-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed deleted file mode 100644 index 79cd1eb8..00000000 --- a/examples/33-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed +++ /dev/null @@ -1,23 +0,0 @@ -struct Some[T](value: T) {} - -struct None() {} - -sumtype Option[T] = Some[T] | None; - -pub fun main() ! Io -> Unit { - printOption!(Some("hello, world!")); - printOption!(None()); -} - -fun printOption(option: Option[String]) !Io -> Unit { - when (option) { - is Some { - print!("Some("); - print!(option.value); - print!(")\n"); - } - is None { - print!("None\n"); - } - } -} diff --git a/examples/33-generic-sums/shed-examples.json5 b/examples/33-generic-sums/shed-examples.json5 new file mode 100644 index 00000000..4a4b2b7c --- /dev/null +++ b/examples/33-generic-sums/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "Some(hello, world!)\nNone", + }, + ], +} diff --git a/examples/33-generic-sums/shed.json5 b/examples/33-generic-sums/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/33-generic-sums/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/33-generic-sums/src/HelloWorld.shed b/examples/33-generic-sums/src/HelloWorld.shed new file mode 100644 index 00000000..e10456bd --- /dev/null +++ b/examples/33-generic-sums/src/HelloWorld.shed @@ -0,0 +1,23 @@ +struct Some[T](value: T) {} + +struct None() {} + +sumtype Option[T] = Some[T] | None; + +pub fun main() ! Io -> Unit { + printOption!(Some[String]("hello, world!")); + printOption!(None()); +} + +fun printOption(option: Option[String]) !Io -> Unit { + when (option) { + is Some[String] { + print!("Some("); + print!(option.value); + print!(")\n"); + } + is None { + print!("None\n"); + } + } +} diff --git a/examples/34-generic-functions/shed-examples.json5 b/examples/34-generic-functions/shed-examples.json5 deleted file mode 100644 index 52763f4c..00000000 --- a/examples/34-generic-functions/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world!", - }, - ], -} diff --git a/examples/34-generic-functions/shed.json5 b/examples/34-generic-functions/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/34-generic-functions/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/34-generic-functions/src/HelloWorld.shed b/examples/34-generic-functions/src/HelloWorld.shed deleted file mode 100644 index d40e9103..00000000 --- a/examples/34-generic-functions/src/HelloWorld.shed +++ /dev/null @@ -1,15 +0,0 @@ -pub fun main() ! Io -> Unit { - val message = compose( - fn (a: String) { a + ", " }, - fn (b: String) { b + "world!\n" }, - )("hello"); - print!(message); -} - -fun compose[A, B, C]( - f: fn (A) -> B, - g: fn (B) -> C -) -> fn (A) -> C { - fn (a) { g(f(a)) } -} - diff --git a/examples/34-generic-structs-and-sums-inferred-type-args/shed-examples.json5 b/examples/34-generic-structs-and-sums-inferred-type-args/shed-examples.json5 new file mode 100644 index 00000000..4a4b2b7c --- /dev/null +++ b/examples/34-generic-structs-and-sums-inferred-type-args/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "Some(hello, world!)\nNone", + }, + ], +} diff --git a/examples/34-generic-structs-and-sums-inferred-type-args/shed.json5 b/examples/34-generic-structs-and-sums-inferred-type-args/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/34-generic-structs-and-sums-inferred-type-args/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/34-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed b/examples/34-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed new file mode 100644 index 00000000..79cd1eb8 --- /dev/null +++ b/examples/34-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed @@ -0,0 +1,23 @@ +struct Some[T](value: T) {} + +struct None() {} + +sumtype Option[T] = Some[T] | None; + +pub fun main() ! Io -> Unit { + printOption!(Some("hello, world!")); + printOption!(None()); +} + +fun printOption(option: Option[String]) !Io -> Unit { + when (option) { + is Some { + print!("Some("); + print!(option.value); + print!(")\n"); + } + is None { + print!("None\n"); + } + } +} diff --git a/examples/35-generic-effects/shed-examples.json5 b/examples/35-generic-effects/shed-examples.json5 deleted file mode 100644 index d104124f..00000000 --- a/examples/35-generic-effects/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello\nhello", - }, - ], -} diff --git a/examples/35-generic-effects/shed.json5 b/examples/35-generic-effects/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/35-generic-effects/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/35-generic-effects/src/HelloWorld.shed b/examples/35-generic-effects/src/HelloWorld.shed deleted file mode 100644 index a54803c6..00000000 --- a/examples/35-generic-effects/src/HelloWorld.shed +++ /dev/null @@ -1,11 +0,0 @@ -pub fun main() ! Io -> Unit { - twice!(fn () ! Io { - print!("hello\n") - }); -} - -fun twice[!E](f: fn () ! E -> Unit) ! E -> Unit { - f!(); - f!(); -} - diff --git a/examples/35-generic-functions/shed-examples.json5 b/examples/35-generic-functions/shed-examples.json5 new file mode 100644 index 00000000..52763f4c --- /dev/null +++ b/examples/35-generic-functions/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world!", + }, + ], +} diff --git a/examples/35-generic-functions/shed.json5 b/examples/35-generic-functions/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/35-generic-functions/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/35-generic-functions/src/HelloWorld.shed b/examples/35-generic-functions/src/HelloWorld.shed new file mode 100644 index 00000000..d40e9103 --- /dev/null +++ b/examples/35-generic-functions/src/HelloWorld.shed @@ -0,0 +1,15 @@ +pub fun main() ! Io -> Unit { + val message = compose( + fn (a: String) { a + ", " }, + fn (b: String) { b + "world!\n" }, + )("hello"); + print!(message); +} + +fun compose[A, B, C]( + f: fn (A) -> B, + g: fn (B) -> C +) -> fn (A) -> C { + fn (a) { g(f(a)) } +} + diff --git a/examples/36-generic-effects/shed-examples.json5 b/examples/36-generic-effects/shed-examples.json5 new file mode 100644 index 00000000..d104124f --- /dev/null +++ b/examples/36-generic-effects/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello\nhello", + }, + ], +} diff --git a/examples/36-generic-effects/shed.json5 b/examples/36-generic-effects/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/36-generic-effects/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/36-generic-effects/src/HelloWorld.shed b/examples/36-generic-effects/src/HelloWorld.shed new file mode 100644 index 00000000..a54803c6 --- /dev/null +++ b/examples/36-generic-effects/src/HelloWorld.shed @@ -0,0 +1,11 @@ +pub fun main() ! Io -> Unit { + twice!(fn () ! Io { + print!("hello\n") + }); +} + +fun twice[!E](f: fn () ! E -> Unit) ! E -> Unit { + f!(); + f!(); +} + diff --git a/examples/36-struct-methods/shed-examples.json5 b/examples/36-struct-methods/shed-examples.json5 deleted file mode 100644 index 95fb0a97..00000000 --- a/examples/36-struct-methods/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "one\ntwo\nmany", - }, - ], -} diff --git a/examples/36-struct-methods/shed.json5 b/examples/36-struct-methods/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/36-struct-methods/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/36-struct-methods/src/HelloWorld.shed b/examples/36-struct-methods/src/HelloWorld.shed deleted file mode 100644 index cfba064d..00000000 --- a/examples/36-struct-methods/src/HelloWorld.shed +++ /dev/null @@ -1,17 +0,0 @@ -pub fun main() ! Io -> Unit { - print!(Count(1).message()); - print!(Count(2).message()); - print!(Count(3).message()); -} - -struct Count(value: Int) { - fun message(this) -> String { - if (this.value == 1) { - "one\n" - } else if (this.value == 2) { - "two\n" - } else { - "many\n" - } - } -} diff --git a/examples/37-struct-method-references/shed-examples.json5 b/examples/37-struct-method-references/shed-examples.json5 deleted file mode 100644 index a57c4749..00000000 --- a/examples/37-struct-method-references/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "one apple\ntwo bananas\nmany coconuts!", - }, - ], -} diff --git a/examples/37-struct-method-references/shed.json5 b/examples/37-struct-method-references/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/37-struct-method-references/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/37-struct-method-references/src/HelloWorld.shed b/examples/37-struct-method-references/src/HelloWorld.shed deleted file mode 100644 index 5bfd3631..00000000 --- a/examples/37-struct-method-references/src/HelloWorld.shed +++ /dev/null @@ -1,25 +0,0 @@ -pub fun main() ! Io -> Unit { - val one = Count(1).message; - val two = Count(2).message; - val three = Count(3).message; - - print!(one("apple", .exclaim = false)); - print!(two("bananas", .exclaim = false)); - print!(three("coconuts", .exclaim = true)); -} - -struct Count(value: Int) { - fun message(this, noun: String, .exclaim: Bool) -> String { - val prefix = if (this.value == 1) { - "one" - } else if (this.value == 2) { - "two" - } else { - "many" - }; - - val exclamation = if (exclaim) { "!" } else { "" }; - - prefix + " " + noun + exclamation + "\n" - } -} diff --git a/examples/37-struct-methods/shed-examples.json5 b/examples/37-struct-methods/shed-examples.json5 new file mode 100644 index 00000000..95fb0a97 --- /dev/null +++ b/examples/37-struct-methods/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "one\ntwo\nmany", + }, + ], +} diff --git a/examples/37-struct-methods/shed.json5 b/examples/37-struct-methods/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/37-struct-methods/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/37-struct-methods/src/HelloWorld.shed b/examples/37-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..cfba064d --- /dev/null +++ b/examples/37-struct-methods/src/HelloWorld.shed @@ -0,0 +1,17 @@ +pub fun main() ! Io -> Unit { + print!(Count(1).message()); + print!(Count(2).message()); + print!(Count(3).message()); +} + +struct Count(value: Int) { + fun message(this) -> String { + if (this.value == 1) { + "one\n" + } else if (this.value == 2) { + "two\n" + } else { + "many\n" + } + } +} diff --git a/examples/38-generic-struct-methods/shed-examples.json5 b/examples/38-generic-struct-methods/shed-examples.json5 deleted file mode 100644 index 531c665f..00000000 --- a/examples/38-generic-struct-methods/shed-examples.json5 +++ /dev/null @@ -1,9 +0,0 @@ -{ - examples: [ - { - project: ".", - bin: "hello-world", - expectedOutput: "hello, world", - }, - ], -} diff --git a/examples/38-generic-struct-methods/shed.json5 b/examples/38-generic-struct-methods/shed.json5 deleted file mode 100644 index a6c8e563..00000000 --- a/examples/38-generic-struct-methods/shed.json5 +++ /dev/null @@ -1,8 +0,0 @@ -{ - bins: [ - { - name: "hello-world", - mainNamespace: "HelloWorld", - }, - ], -} diff --git a/examples/38-generic-struct-methods/src/HelloWorld.shed b/examples/38-generic-struct-methods/src/HelloWorld.shed deleted file mode 100644 index a4e808e1..00000000 --- a/examples/38-generic-struct-methods/src/HelloWorld.shed +++ /dev/null @@ -1,11 +0,0 @@ -pub fun main() ! Io -> Unit { - val messageBox = Box("hello, world"); - - print!(messageBox.get()); -} - -struct Box[T](value: T) { - fun get(this) -> T { - this.value - } -} diff --git a/examples/38-struct-method-references/shed-examples.json5 b/examples/38-struct-method-references/shed-examples.json5 new file mode 100644 index 00000000..a57c4749 --- /dev/null +++ b/examples/38-struct-method-references/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "one apple\ntwo bananas\nmany coconuts!", + }, + ], +} diff --git a/examples/38-struct-method-references/shed.json5 b/examples/38-struct-method-references/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/38-struct-method-references/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/38-struct-method-references/src/HelloWorld.shed b/examples/38-struct-method-references/src/HelloWorld.shed new file mode 100644 index 00000000..5bfd3631 --- /dev/null +++ b/examples/38-struct-method-references/src/HelloWorld.shed @@ -0,0 +1,25 @@ +pub fun main() ! Io -> Unit { + val one = Count(1).message; + val two = Count(2).message; + val three = Count(3).message; + + print!(one("apple", .exclaim = false)); + print!(two("bananas", .exclaim = false)); + print!(three("coconuts", .exclaim = true)); +} + +struct Count(value: Int) { + fun message(this, noun: String, .exclaim: Bool) -> String { + val prefix = if (this.value == 1) { + "one" + } else if (this.value == 2) { + "two" + } else { + "many" + }; + + val exclamation = if (exclaim) { "!" } else { "" }; + + prefix + " " + noun + exclamation + "\n" + } +} diff --git a/examples/39-generic-struct-methods/shed-examples.json5 b/examples/39-generic-struct-methods/shed-examples.json5 new file mode 100644 index 00000000..531c665f --- /dev/null +++ b/examples/39-generic-struct-methods/shed-examples.json5 @@ -0,0 +1,9 @@ +{ + examples: [ + { + project: ".", + bin: "hello-world", + expectedOutput: "hello, world", + }, + ], +} diff --git a/examples/39-generic-struct-methods/shed.json5 b/examples/39-generic-struct-methods/shed.json5 new file mode 100644 index 00000000..a6c8e563 --- /dev/null +++ b/examples/39-generic-struct-methods/shed.json5 @@ -0,0 +1,8 @@ +{ + bins: [ + { + name: "hello-world", + mainNamespace: "HelloWorld", + }, + ], +} diff --git a/examples/39-generic-struct-methods/src/HelloWorld.shed b/examples/39-generic-struct-methods/src/HelloWorld.shed new file mode 100644 index 00000000..a4e808e1 --- /dev/null +++ b/examples/39-generic-struct-methods/src/HelloWorld.shed @@ -0,0 +1,11 @@ +pub fun main() ! Io -> Unit { + val messageBox = Box("hello, world"); + + print!(messageBox.get()); +} + +struct Box[T](value: T) { + fun get(this) -> T { + this.value + } +} -- cgit v1.2.3