ava/enumerations.md

530 B

Enumerations

Enumerations are sum types.

Example: The Option Type

enum Option[A] is
    record Some[A] is (value: A)
    object None

fn some[A]: (a: A) => Some[A] is a => Some(a)

Example: The Either Type

TODO: Describe import behavior! Does importing Either import Left/Right?

enum Either[L, R] is
    record Left[L] is { value: L }
    record Right[R] is { value: R }

fn left[L]: (left: L) => Either[L, Nothing] is l => Left { l }
fn right[R]: (right: R) => Either[Nothing, R] is r => Right { r }