either.h¶
A choice type with two cases.
Defines
-
ML99_left(x)¶
The left value
x
.
-
ML99_right(x)¶
The right value
x
.
-
ML99_isLeft(either)¶
ML99_true()
ifeither
contains a left value, otherwiseML99_false()
.Examples
#include <metalang99/either.h> // 1 ML99_isLeft(ML99_left(v(123))) // 0 ML99_isLeft(ML99_right(v(123)))
-
ML99_isRight(either)¶
The inverse of ML99_isLeft.
Examples
#include <metalang99/either.h> // 1 ML99_isRight(ML99_right(v(123))) // 0 ML99_isRight(ML99_left(v(123)))
-
ML99_eitherEq(cmp, either, other)¶
Tests
either
andother
for equality.Examples
#include <metalang99/either.h> #include <metalang99/nat.h> // 1 ML99_eitherEq(v(ML99_natEq), ML99_left(v(123)), ML99_left(v(123))) // 0 ML99_eitherEq(v(ML99_natEq), ML99_right(v(123)), ML99_left(v(8))) // 0 ML99_eitherEq(v(ML99_natEq), ML99_right(v(123)), ML99_left(v(123)))
-
ML99_unwrapLeft(either)¶
Returns the left value on
ML99_left(x)
or emits a fatal error onML99_right(y)
.Examples
#include <metalang99/either.h> // 123 ML99_unwrapLeft(ML99_left(v(123))) // Emits a fatal error. ML99_unwrapLeft(ML99_right(v(123)))
-
ML99_unwrapRight(either)¶
The inverse of ML99_unwrapLeft.
Examples
#include <metalang99/either.h> // 123 ML99_unwrapRight(ML99_right(v(123))) // Emits a fatal error. ML99_unwrapRight(ML99_left(v(123)))
-
ML99_LEFT(x)¶
-
ML99_RIGHT(x)¶
-
ML99_IS_LEFT(either)¶
-
ML99_IS_RIGHT(either)¶