diff options
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"); + } + } +} |
