diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-10-08 20:50:40 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-10-08 20:50:40 +0100 |
| commit | fa2bd5fe73d359364e7b897f438a84bcd85fb5ed (patch) | |
| tree | 402f5c10f1bfcc37b6807d89d7217124d4ff6dad /examples | |
| parent | b8b4814b92c4d808da5a79d1d7311c27b325853f (diff) | |
Add sums example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/15-sums/shed.toml | 9 | ||||
| -rw-r--r-- | examples/15-sums/src/HelloWorld.shed | 23 |
2 files changed, 32 insertions, 0 deletions
diff --git a/examples/15-sums/shed.toml b/examples/15-sums/shed.toml new file mode 100644 index 00000000..3a2d316f --- /dev/null +++ b/examples/15-sums/shed.toml @@ -0,0 +1,9 @@ +[shed] +main = "HelloWorld" + +[[shed.bins]] +name = "hello-world" + +[[shed.examples]] +bin = "hello-world" +expected-output = "Some(hello, world!)\nNone" diff --git a/examples/15-sums/src/HelloWorld.shed b/examples/15-sums/src/HelloWorld.shed new file mode 100644 index 00000000..3dd7038d --- /dev/null +++ b/examples/15-sums/src/HelloWorld.shed @@ -0,0 +1,23 @@ +struct Some(.value: String) {} + +struct None() {} + +sumtype Option = Some | None; + +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"); + } + } +} |
