aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/30-generic-sums/shed.toml7
-rw-r--r--examples/30-generic-sums/src/HelloWorld.shed23
2 files changed, 30 insertions, 0 deletions
diff --git a/examples/30-generic-sums/shed.toml b/examples/30-generic-sums/shed.toml
new file mode 100644
index 00000000..842e1e9c
--- /dev/null
+++ b/examples/30-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/30-generic-sums/src/HelloWorld.shed b/examples/30-generic-sums/src/HelloWorld.shed
new file mode 100644
index 00000000..314546b5
--- /dev/null
+++ b/examples/30-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");
+ }
+ }
+}