04 / Playground

Delete the abstain branch. See what happens.

The browser playground ships with the reference interpreter (v0.2), so this page cannot run code yet. Below: the program and what the interpreter is specified to print, including the compile error you get when the abstain branch is removed.

main.dvprogram
let atlas = { "France": "Paris", "Japan": "Tokyo", "Kenya": "Nairobi" }

fn capital(country: Text) -> Text? {
  know atlas[country] => it
  else => abstain "no record for {country}"
}

for c in ["Japan", "Atlantis", "Kenya"] {
  match capital(c) {
    known v   => print("{c}: {v}")
    abstain r => print("{c}: abstained ({r})")
  }
}
outputexpected
Japan: Tokyo
Atlantis: abstained (no record for Atlantis)
Kenya: Nairobi
experiment

Now remove the abstain arm

main.dv (edited)
match capital(c) {
  known v => print("{c}: {v}")
}
dv checkerror
error[E013]: non-exhaustive match
 --> main.dv:9:3
  |
9 |   match capital(c) {
  |         ^^^^^^^^^^ missing arm: `abstain`
  |
note: `capital` returns Text?, which can abstain