Pattern matching

Chapter: Pattern matching

  • errors and optional results are special cases of pattern matching; this chapter covers all types; interested readers can jump ahead and back as needed.

  • point: unhandled errors are a special case of non-exhaustive pattern match (for results and option types)

  • point: null-pointer errors are a special case of non-exhaustive pattern match

  • the Motoko type checker statically enforces exhaustive pattern matches for all optional types (and variants); hence, null-pointer errors are ruled out statically, and are impossible dynamically.