From e0bbcd3fb41b54f8d72bf2d08a592def2e44d3b7 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 10 Dec 2024 23:22:20 +0000 Subject: Add disabled example for struct positional fields --- examples/16-struct-positional-fields/shed.toml | 7 ++++ .../src/HelloWorld.shed | 15 ++++++++ examples/16-sums/shed.toml | 7 ---- examples/16-sums/src/HelloWorld.shed | 23 ----------- examples/17-import/shed.toml | 7 ---- examples/17-import/src/HelloWorld.shed | 5 --- examples/17-import/src/Message.shed | 1 - examples/17-sums/shed.toml | 7 ++++ examples/17-sums/src/HelloWorld.shed | 23 +++++++++++ examples/18-function-expression/shed.toml | 7 ---- .../18-function-expression/src/HelloWorld.shed | 11 ------ examples/18-import/shed.toml | 7 ++++ examples/18-import/src/HelloWorld.shed | 5 +++ examples/18-import/src/Message.shed | 1 + .../shed.toml | 7 ---- .../src/HelloWorld.shed | 4 -- examples/19-function-expression/shed.toml | 7 ++++ .../19-function-expression/src/HelloWorld.shed | 11 ++++++ .../shed.toml | 7 ---- .../src/HelloWorld.shed | 8 ---- .../shed.toml | 7 ++++ .../src/HelloWorld.shed | 4 ++ examples/21-effect-resume/shed.toml | 7 ---- examples/21-effect-resume/src/HelloWorld.shed | 23 ----------- .../shed.toml | 7 ++++ .../src/HelloWorld.shed | 8 ++++ examples/22-effect-resume-with-value/shed.toml | 7 ---- .../src/HelloWorld.shed | 21 ----------- examples/22-effect-resume/shed.toml | 7 ++++ examples/22-effect-resume/src/HelloWorld.shed | 23 +++++++++++ examples/23-effect-resume-with-value/shed.toml | 7 ++++ .../src/HelloWorld.shed | 21 +++++++++++ examples/23-effect-with-state/shed.toml | 7 ---- examples/23-effect-with-state/src/HelloWorld.shed | 22 ----------- examples/24-effect-handler-pop/shed.toml | 7 ---- examples/24-effect-handler-pop/src/HelloWorld.shed | 36 ------------------ examples/24-effect-with-state/shed.toml | 7 ++++ examples/24-effect-with-state/src/HelloWorld.shed | 22 +++++++++++ examples/25-effect-handler-pop-on-return/shed.toml | 7 ---- .../src/HelloWorld.shed | 41 -------------------- examples/25-effect-handler-pop/shed.toml | 7 ++++ examples/25-effect-handler-pop/src/HelloWorld.shed | 36 ++++++++++++++++++ examples/26-effect-handler-nested/shed.toml | 7 ---- examples/26-effect-handler-nested/src/Example.shed | 42 --------------------- examples/26-effect-handler-pop-on-return/shed.toml | 7 ++++ .../src/HelloWorld.shed | 41 ++++++++++++++++++++ examples/27-effect-handler-nested/shed.toml | 7 ++++ examples/27-effect-handler-nested/src/Example.shed | 42 +++++++++++++++++++++ examples/27-effect-in-handler/shed.toml | 7 ---- examples/27-effect-in-handler/src/Example.shed | 44 ---------------------- examples/28-effect-break/shed.toml | 7 ---- examples/28-effect-break/src/HelloWorld.shed | 27 ------------- examples/28-effect-in-handler/shed.toml | 7 ++++ examples/28-effect-in-handler/src/Example.shed | 44 ++++++++++++++++++++++ examples/29-effect-break/shed.toml | 7 ++++ examples/29-effect-break/src/HelloWorld.shed | 27 +++++++++++++ examples/29-generic-structs/shed.toml | 7 ---- examples/29-generic-structs/src/HelloWorld.shed | 15 -------- examples/30-generic-structs/shed.toml | 7 ++++ examples/30-generic-structs/src/HelloWorld.shed | 15 ++++++++ examples/30-generic-sums/shed.toml | 7 ---- examples/30-generic-sums/src/HelloWorld.shed | 23 ----------- .../shed.toml | 7 ---- .../src/HelloWorld.shed | 23 ----------- examples/31-generic-sums/shed.toml | 7 ++++ examples/31-generic-sums/src/HelloWorld.shed | 23 +++++++++++ examples/32-generic-functions/shed.toml | 7 ---- examples/32-generic-functions/src/HelloWorld.shed | 15 -------- .../shed.toml | 7 ++++ .../src/HelloWorld.shed | 23 +++++++++++ examples/33-generic-effects/shed.toml | 7 ---- examples/33-generic-effects/src/HelloWorld.shed | 11 ------ examples/33-generic-functions/shed.toml | 7 ++++ examples/33-generic-functions/src/HelloWorld.shed | 15 ++++++++ examples/34-generic-effects/shed.toml | 7 ++++ examples/34-generic-effects/src/HelloWorld.shed | 11 ++++++ examples/35-extensions/shed.toml | 7 ---- examples/35-extensions/src/HelloWorld.shed | 20 ---------- examples/36-extensions/shed.toml | 7 ++++ examples/36-extensions/src/HelloWorld.shed | 20 ++++++++++ 80 files changed, 570 insertions(+), 548 deletions(-) create mode 100644 examples/16-struct-positional-fields/shed.toml create mode 100644 examples/16-struct-positional-fields/src/HelloWorld.shed delete mode 100644 examples/16-sums/shed.toml delete mode 100644 examples/16-sums/src/HelloWorld.shed delete mode 100644 examples/17-import/shed.toml delete mode 100644 examples/17-import/src/HelloWorld.shed delete mode 100644 examples/17-import/src/Message.shed create mode 100644 examples/17-sums/shed.toml create mode 100644 examples/17-sums/src/HelloWorld.shed delete mode 100644 examples/18-function-expression/shed.toml delete mode 100644 examples/18-function-expression/src/HelloWorld.shed create mode 100644 examples/18-import/shed.toml create mode 100644 examples/18-import/src/HelloWorld.shed create mode 100644 examples/18-import/src/Message.shed delete mode 100644 examples/19-function-expression-infer-return-type/shed.toml delete mode 100644 examples/19-function-expression-infer-return-type/src/HelloWorld.shed create mode 100644 examples/19-function-expression/shed.toml create mode 100644 examples/19-function-expression/src/HelloWorld.shed delete mode 100644 examples/20-function-expression-infer-param-type/shed.toml delete mode 100644 examples/20-function-expression-infer-param-type/src/HelloWorld.shed create mode 100644 examples/20-function-expression-infer-return-type/shed.toml create mode 100644 examples/20-function-expression-infer-return-type/src/HelloWorld.shed delete mode 100644 examples/21-effect-resume/shed.toml delete mode 100644 examples/21-effect-resume/src/HelloWorld.shed create mode 100644 examples/21-function-expression-infer-param-type/shed.toml create mode 100644 examples/21-function-expression-infer-param-type/src/HelloWorld.shed delete mode 100644 examples/22-effect-resume-with-value/shed.toml delete mode 100644 examples/22-effect-resume-with-value/src/HelloWorld.shed create mode 100644 examples/22-effect-resume/shed.toml create mode 100644 examples/22-effect-resume/src/HelloWorld.shed create mode 100644 examples/23-effect-resume-with-value/shed.toml create mode 100644 examples/23-effect-resume-with-value/src/HelloWorld.shed delete mode 100644 examples/23-effect-with-state/shed.toml delete mode 100644 examples/23-effect-with-state/src/HelloWorld.shed delete mode 100644 examples/24-effect-handler-pop/shed.toml delete mode 100644 examples/24-effect-handler-pop/src/HelloWorld.shed create mode 100644 examples/24-effect-with-state/shed.toml create mode 100644 examples/24-effect-with-state/src/HelloWorld.shed delete mode 100644 examples/25-effect-handler-pop-on-return/shed.toml delete mode 100644 examples/25-effect-handler-pop-on-return/src/HelloWorld.shed create mode 100644 examples/25-effect-handler-pop/shed.toml create mode 100644 examples/25-effect-handler-pop/src/HelloWorld.shed delete mode 100644 examples/26-effect-handler-nested/shed.toml delete mode 100644 examples/26-effect-handler-nested/src/Example.shed create mode 100644 examples/26-effect-handler-pop-on-return/shed.toml create mode 100644 examples/26-effect-handler-pop-on-return/src/HelloWorld.shed create mode 100644 examples/27-effect-handler-nested/shed.toml create mode 100644 examples/27-effect-handler-nested/src/Example.shed delete mode 100644 examples/27-effect-in-handler/shed.toml delete mode 100644 examples/27-effect-in-handler/src/Example.shed delete mode 100644 examples/28-effect-break/shed.toml delete mode 100644 examples/28-effect-break/src/HelloWorld.shed create mode 100644 examples/28-effect-in-handler/shed.toml create mode 100644 examples/28-effect-in-handler/src/Example.shed create mode 100644 examples/29-effect-break/shed.toml create mode 100644 examples/29-effect-break/src/HelloWorld.shed delete mode 100644 examples/29-generic-structs/shed.toml delete mode 100644 examples/29-generic-structs/src/HelloWorld.shed create mode 100644 examples/30-generic-structs/shed.toml create mode 100644 examples/30-generic-structs/src/HelloWorld.shed delete mode 100644 examples/30-generic-sums/shed.toml delete mode 100644 examples/30-generic-sums/src/HelloWorld.shed delete mode 100644 examples/31-generic-structs-and-sums-inferred-type-args/shed.toml delete mode 100644 examples/31-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed create mode 100644 examples/31-generic-sums/shed.toml create mode 100644 examples/31-generic-sums/src/HelloWorld.shed delete mode 100644 examples/32-generic-functions/shed.toml delete mode 100644 examples/32-generic-functions/src/HelloWorld.shed create mode 100644 examples/32-generic-structs-and-sums-inferred-type-args/shed.toml create mode 100644 examples/32-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed delete mode 100644 examples/33-generic-effects/shed.toml delete mode 100644 examples/33-generic-effects/src/HelloWorld.shed create mode 100644 examples/33-generic-functions/shed.toml create mode 100644 examples/33-generic-functions/src/HelloWorld.shed create mode 100644 examples/34-generic-effects/shed.toml create mode 100644 examples/34-generic-effects/src/HelloWorld.shed delete mode 100644 examples/35-extensions/shed.toml delete mode 100644 examples/35-extensions/src/HelloWorld.shed create mode 100644 examples/36-extensions/shed.toml create mode 100644 examples/36-extensions/src/HelloWorld.shed (limited to 'examples') diff --git a/examples/16-struct-positional-fields/shed.toml b/examples/16-struct-positional-fields/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/16-struct-positional-fields/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/16-struct-positional-fields/src/HelloWorld.shed b/examples/16-struct-positional-fields/src/HelloWorld.shed new file mode 100644 index 00000000..ad6fe426 --- /dev/null +++ b/examples/16-struct-positional-fields/src/HelloWorld.shed @@ -0,0 +1,15 @@ +pub fun main() ! Io -> Unit { + val messageParts = getMessageParts(); + print!(messageParts.part1); + print!(messageParts.part2); +} + +struct MessageParts( + part1: String, + part2: String, +) { +} + +fun getMessageParts() -> MessageParts { + MessageParts("hello, ", "world\n") +} diff --git a/examples/16-sums/shed.toml b/examples/16-sums/shed.toml deleted file mode 100644 index 842e1e9c..00000000 --- a/examples/16-sums/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "Some(hello, world!)\nNone" diff --git a/examples/16-sums/src/HelloWorld.shed b/examples/16-sums/src/HelloWorld.shed deleted file mode 100644 index 58177d9f..00000000 --- a/examples/16-sums/src/HelloWorld.shed +++ /dev/null @@ -1,23 +0,0 @@ -struct Some(.value: String) {} - -struct None() {} - -sumtype Option = Some | None; - -pub fun main() ! Io -> Unit { - printOption!(Some(.value = "hello, world!")); - printOption!(None()); -} - -fun printOption(option: Option) !Io -> Unit { - when (option) { - is Some { - print!("Some("); - print!(option.value); - print!(")\n"); - } - is None { - print!("None\n"); - } - } -} diff --git a/examples/17-import/shed.toml b/examples/17-import/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/17-import/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/17-import/src/HelloWorld.shed b/examples/17-import/src/HelloWorld.shed deleted file mode 100644 index 8cebf604..00000000 --- a/examples/17-import/src/HelloWorld.shed +++ /dev/null @@ -1,5 +0,0 @@ -import Message; - -pub fun main() ! Io -> Unit { - print!(Message.message); -} diff --git a/examples/17-import/src/Message.shed b/examples/17-import/src/Message.shed deleted file mode 100644 index db03110a..00000000 --- a/examples/17-import/src/Message.shed +++ /dev/null @@ -1 +0,0 @@ -pub val message = "hello, world\n"; diff --git a/examples/17-sums/shed.toml b/examples/17-sums/shed.toml new file mode 100644 index 00000000..842e1e9c --- /dev/null +++ b/examples/17-sums/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "Some(hello, world!)\nNone" diff --git a/examples/17-sums/src/HelloWorld.shed b/examples/17-sums/src/HelloWorld.shed new file mode 100644 index 00000000..58177d9f --- /dev/null +++ b/examples/17-sums/src/HelloWorld.shed @@ -0,0 +1,23 @@ +struct Some(.value: String) {} + +struct None() {} + +sumtype Option = Some | None; + +pub fun main() ! Io -> Unit { + printOption!(Some(.value = "hello, world!")); + printOption!(None()); +} + +fun printOption(option: Option) !Io -> Unit { + when (option) { + is Some { + print!("Some("); + print!(option.value); + print!(")\n"); + } + is None { + print!("None\n"); + } + } +} diff --git a/examples/18-function-expression/shed.toml b/examples/18-function-expression/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/18-function-expression/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/18-function-expression/src/HelloWorld.shed b/examples/18-function-expression/src/HelloWorld.shed deleted file mode 100644 index 1ebb2863..00000000 --- a/examples/18-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/18-import/shed.toml b/examples/18-import/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/18-import/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/18-import/src/HelloWorld.shed b/examples/18-import/src/HelloWorld.shed new file mode 100644 index 00000000..8cebf604 --- /dev/null +++ b/examples/18-import/src/HelloWorld.shed @@ -0,0 +1,5 @@ +import Message; + +pub fun main() ! Io -> Unit { + print!(Message.message); +} diff --git a/examples/18-import/src/Message.shed b/examples/18-import/src/Message.shed new file mode 100644 index 00000000..db03110a --- /dev/null +++ b/examples/18-import/src/Message.shed @@ -0,0 +1 @@ +pub val message = "hello, world\n"; diff --git a/examples/19-function-expression-infer-return-type/shed.toml b/examples/19-function-expression-infer-return-type/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/19-function-expression-infer-return-type/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/19-function-expression-infer-return-type/src/HelloWorld.shed b/examples/19-function-expression-infer-return-type/src/HelloWorld.shed deleted file mode 100644 index 1c93c946..00000000 --- a/examples/19-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/19-function-expression/shed.toml b/examples/19-function-expression/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/19-function-expression/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/19-function-expression/src/HelloWorld.shed b/examples/19-function-expression/src/HelloWorld.shed new file mode 100644 index 00000000..1ebb2863 --- /dev/null +++ b/examples/19-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/20-function-expression-infer-param-type/shed.toml b/examples/20-function-expression-infer-param-type/shed.toml deleted file mode 100644 index 1503d826..00000000 --- a/examples/20-function-expression-infer-param-type/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world\nworld, hello" diff --git a/examples/20-function-expression-infer-param-type/src/HelloWorld.shed b/examples/20-function-expression-infer-param-type/src/HelloWorld.shed deleted file mode 100644 index e91bc5e0..00000000 --- a/examples/20-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/20-function-expression-infer-return-type/shed.toml b/examples/20-function-expression-infer-return-type/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/20-function-expression-infer-return-type/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/20-function-expression-infer-return-type/src/HelloWorld.shed b/examples/20-function-expression-infer-return-type/src/HelloWorld.shed new file mode 100644 index 00000000..1c93c946 --- /dev/null +++ b/examples/20-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/21-effect-resume/shed.toml b/examples/21-effect-resume/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/21-effect-resume/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/21-effect-resume/src/HelloWorld.shed b/examples/21-effect-resume/src/HelloWorld.shed deleted file mode 100644 index a5e96e2f..00000000 --- a/examples/21-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/21-function-expression-infer-param-type/shed.toml b/examples/21-function-expression-infer-param-type/shed.toml new file mode 100644 index 00000000..1503d826 --- /dev/null +++ b/examples/21-function-expression-infer-param-type/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world\nworld, hello" diff --git a/examples/21-function-expression-infer-param-type/src/HelloWorld.shed b/examples/21-function-expression-infer-param-type/src/HelloWorld.shed new file mode 100644 index 00000000..e91bc5e0 --- /dev/null +++ b/examples/21-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/22-effect-resume-with-value/shed.toml b/examples/22-effect-resume-with-value/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/22-effect-resume-with-value/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/22-effect-resume-with-value/src/HelloWorld.shed b/examples/22-effect-resume-with-value/src/HelloWorld.shed deleted file mode 100644 index 3252aaf3..00000000 --- a/examples/22-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/22-effect-resume/shed.toml b/examples/22-effect-resume/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/22-effect-resume/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/22-effect-resume/src/HelloWorld.shed b/examples/22-effect-resume/src/HelloWorld.shed new file mode 100644 index 00000000..a5e96e2f --- /dev/null +++ b/examples/22-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/23-effect-resume-with-value/shed.toml b/examples/23-effect-resume-with-value/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/23-effect-resume-with-value/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/23-effect-resume-with-value/src/HelloWorld.shed b/examples/23-effect-resume-with-value/src/HelloWorld.shed new file mode 100644 index 00000000..3252aaf3 --- /dev/null +++ b/examples/23-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/23-effect-with-state/shed.toml b/examples/23-effect-with-state/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/23-effect-with-state/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/23-effect-with-state/src/HelloWorld.shed b/examples/23-effect-with-state/src/HelloWorld.shed deleted file mode 100644 index 50d64428..00000000 --- a/examples/23-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/24-effect-handler-pop/shed.toml b/examples/24-effect-handler-pop/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/24-effect-handler-pop/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/24-effect-handler-pop/src/HelloWorld.shed b/examples/24-effect-handler-pop/src/HelloWorld.shed deleted file mode 100644 index 2b9491d7..00000000 --- a/examples/24-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/24-effect-with-state/shed.toml b/examples/24-effect-with-state/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/24-effect-with-state/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/24-effect-with-state/src/HelloWorld.shed b/examples/24-effect-with-state/src/HelloWorld.shed new file mode 100644 index 00000000..50d64428 --- /dev/null +++ b/examples/24-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/25-effect-handler-pop-on-return/shed.toml b/examples/25-effect-handler-pop-on-return/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/25-effect-handler-pop-on-return/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/25-effect-handler-pop-on-return/src/HelloWorld.shed b/examples/25-effect-handler-pop-on-return/src/HelloWorld.shed deleted file mode 100644 index 4e91f8b4..00000000 --- a/examples/25-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/25-effect-handler-pop/shed.toml b/examples/25-effect-handler-pop/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/25-effect-handler-pop/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/25-effect-handler-pop/src/HelloWorld.shed b/examples/25-effect-handler-pop/src/HelloWorld.shed new file mode 100644 index 00000000..2b9491d7 --- /dev/null +++ b/examples/25-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/26-effect-handler-nested/shed.toml b/examples/26-effect-handler-nested/shed.toml deleted file mode 100644 index 291ca6db..00000000 --- a/examples/26-effect-handler-nested/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "example" -main-namespace = "Example" - -[[shed.examples]] -bin = "example" -expected-output = "a outer\na inner\na inner\nb\na inner\na inner\na outer" diff --git a/examples/26-effect-handler-nested/src/Example.shed b/examples/26-effect-handler-nested/src/Example.shed deleted file mode 100644 index 2a8e4781..00000000 --- a/examples/26-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/26-effect-handler-pop-on-return/shed.toml b/examples/26-effect-handler-pop-on-return/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/26-effect-handler-pop-on-return/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/26-effect-handler-pop-on-return/src/HelloWorld.shed b/examples/26-effect-handler-pop-on-return/src/HelloWorld.shed new file mode 100644 index 00000000..4e91f8b4 --- /dev/null +++ b/examples/26-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/27-effect-handler-nested/shed.toml b/examples/27-effect-handler-nested/shed.toml new file mode 100644 index 00000000..291ca6db --- /dev/null +++ b/examples/27-effect-handler-nested/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "example" +main-namespace = "Example" + +[[shed.examples]] +bin = "example" +expected-output = "a outer\na inner\na inner\nb\na inner\na inner\na outer" diff --git a/examples/27-effect-handler-nested/src/Example.shed b/examples/27-effect-handler-nested/src/Example.shed new file mode 100644 index 00000000..2a8e4781 --- /dev/null +++ b/examples/27-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/27-effect-in-handler/shed.toml b/examples/27-effect-in-handler/shed.toml deleted file mode 100644 index fc01b961..00000000 --- a/examples/27-effect-in-handler/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "example" -main-namespace = "Example" - -[[shed.examples]] -bin = "example" -expected-output = "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/27-effect-in-handler/src/Example.shed b/examples/27-effect-in-handler/src/Example.shed deleted file mode 100644 index 568d9ea8..00000000 --- a/examples/27-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/28-effect-break/shed.toml b/examples/28-effect-break/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/28-effect-break/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/28-effect-break/src/HelloWorld.shed b/examples/28-effect-break/src/HelloWorld.shed deleted file mode 100644 index f836ab58..00000000 --- a/examples/28-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/28-effect-in-handler/shed.toml b/examples/28-effect-in-handler/shed.toml new file mode 100644 index 00000000..fc01b961 --- /dev/null +++ b/examples/28-effect-in-handler/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "example" +main-namespace = "Example" + +[[shed.examples]] +bin = "example" +expected-output = "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/28-effect-in-handler/src/Example.shed b/examples/28-effect-in-handler/src/Example.shed new file mode 100644 index 00000000..568d9ea8 --- /dev/null +++ b/examples/28-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/29-effect-break/shed.toml b/examples/29-effect-break/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/29-effect-break/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/29-effect-break/src/HelloWorld.shed b/examples/29-effect-break/src/HelloWorld.shed new file mode 100644 index 00000000..f836ab58 --- /dev/null +++ b/examples/29-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/29-generic-structs/shed.toml b/examples/29-generic-structs/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/29-generic-structs/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/29-generic-structs/src/HelloWorld.shed b/examples/29-generic-structs/src/HelloWorld.shed deleted file mode 100644 index f5a2f013..00000000 --- a/examples/29-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/30-generic-structs/shed.toml b/examples/30-generic-structs/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/30-generic-structs/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/30-generic-structs/src/HelloWorld.shed b/examples/30-generic-structs/src/HelloWorld.shed new file mode 100644 index 00000000..f5a2f013 --- /dev/null +++ b/examples/30-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/30-generic-sums/shed.toml b/examples/30-generic-sums/shed.toml deleted file mode 100644 index 842e1e9c..00000000 --- a/examples/30-generic-sums/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "Some(hello, world!)\nNone" diff --git a/examples/30-generic-sums/src/HelloWorld.shed b/examples/30-generic-sums/src/HelloWorld.shed deleted file mode 100644 index 314546b5..00000000 --- a/examples/30-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](.value = "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/31-generic-structs-and-sums-inferred-type-args/shed.toml b/examples/31-generic-structs-and-sums-inferred-type-args/shed.toml deleted file mode 100644 index 842e1e9c..00000000 --- a/examples/31-generic-structs-and-sums-inferred-type-args/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "Some(hello, world!)\nNone" diff --git a/examples/31-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed b/examples/31-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed deleted file mode 100644 index 5a58f8e4..00000000 --- a/examples/31-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(.value = "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/31-generic-sums/shed.toml b/examples/31-generic-sums/shed.toml new file mode 100644 index 00000000..842e1e9c --- /dev/null +++ b/examples/31-generic-sums/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "Some(hello, world!)\nNone" diff --git a/examples/31-generic-sums/src/HelloWorld.shed b/examples/31-generic-sums/src/HelloWorld.shed new file mode 100644 index 00000000..314546b5 --- /dev/null +++ b/examples/31-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](.value = "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/32-generic-functions/shed.toml b/examples/32-generic-functions/shed.toml deleted file mode 100644 index 9c1a6d01..00000000 --- a/examples/32-generic-functions/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world!" diff --git a/examples/32-generic-functions/src/HelloWorld.shed b/examples/32-generic-functions/src/HelloWorld.shed deleted file mode 100644 index d40e9103..00000000 --- a/examples/32-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/32-generic-structs-and-sums-inferred-type-args/shed.toml b/examples/32-generic-structs-and-sums-inferred-type-args/shed.toml new file mode 100644 index 00000000..842e1e9c --- /dev/null +++ b/examples/32-generic-structs-and-sums-inferred-type-args/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "Some(hello, world!)\nNone" diff --git a/examples/32-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed b/examples/32-generic-structs-and-sums-inferred-type-args/src/HelloWorld.shed new file mode 100644 index 00000000..5a58f8e4 --- /dev/null +++ b/examples/32-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(.value = "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-effects/shed.toml b/examples/33-generic-effects/shed.toml deleted file mode 100644 index 04d4475a..00000000 --- a/examples/33-generic-effects/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello\nhello" diff --git a/examples/33-generic-effects/src/HelloWorld.shed b/examples/33-generic-effects/src/HelloWorld.shed deleted file mode 100644 index a54803c6..00000000 --- a/examples/33-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/33-generic-functions/shed.toml b/examples/33-generic-functions/shed.toml new file mode 100644 index 00000000..9c1a6d01 --- /dev/null +++ b/examples/33-generic-functions/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world!" diff --git a/examples/33-generic-functions/src/HelloWorld.shed b/examples/33-generic-functions/src/HelloWorld.shed new file mode 100644 index 00000000..d40e9103 --- /dev/null +++ b/examples/33-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/34-generic-effects/shed.toml b/examples/34-generic-effects/shed.toml new file mode 100644 index 00000000..04d4475a --- /dev/null +++ b/examples/34-generic-effects/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello\nhello" diff --git a/examples/34-generic-effects/src/HelloWorld.shed b/examples/34-generic-effects/src/HelloWorld.shed new file mode 100644 index 00000000..a54803c6 --- /dev/null +++ b/examples/34-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/35-extensions/shed.toml b/examples/35-extensions/shed.toml deleted file mode 100644 index bf5c13c4..00000000 --- a/examples/35-extensions/shed.toml +++ /dev/null @@ -1,7 +0,0 @@ -[[shed.bins]] -name = "hello-world" -main-namespace = "HelloWorld" - -[[shed.examples]] -bin = "hello-world" -expected-output = "hello, world" diff --git a/examples/35-extensions/src/HelloWorld.shed b/examples/35-extensions/src/HelloWorld.shed deleted file mode 100644 index d1ad01be..00000000 --- a/examples/35-extensions/src/HelloWorld.shed +++ /dev/null @@ -1,20 +0,0 @@ -pub fun main() ! Io -> Unit { - print!(Count(.value = 1).message()); - print!(Count(.value = 2).message()); - print!(Count(.value = 3).message()); -} - -struct Count(.value: Int) { -} - -extend Count { - fun message(this) -> String { - if (count == 1) { - "one\n" - } else if (count == 2) { - "two\n" - } else { - "many\n" - } - } -} diff --git a/examples/36-extensions/shed.toml b/examples/36-extensions/shed.toml new file mode 100644 index 00000000..bf5c13c4 --- /dev/null +++ b/examples/36-extensions/shed.toml @@ -0,0 +1,7 @@ +[[shed.bins]] +name = "hello-world" +main-namespace = "HelloWorld" + +[[shed.examples]] +bin = "hello-world" +expected-output = "hello, world" diff --git a/examples/36-extensions/src/HelloWorld.shed b/examples/36-extensions/src/HelloWorld.shed new file mode 100644 index 00000000..d1ad01be --- /dev/null +++ b/examples/36-extensions/src/HelloWorld.shed @@ -0,0 +1,20 @@ +pub fun main() ! Io -> Unit { + print!(Count(.value = 1).message()); + print!(Count(.value = 2).message()); + print!(Count(.value = 3).message()); +} + +struct Count(.value: Int) { +} + +extend Count { + fun message(this) -> String { + if (count == 1) { + "one\n" + } else if (count == 2) { + "two\n" + } else { + "many\n" + } + } +} -- cgit v1.2.3