Loading...
Searching...
No Matches
either.h File Reference

A choice type with two cases. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Macros

#define | ML99_left(x) ML99_call(ML99_left, x)
| The left value `x`.
#define | ML99_right(x) ML99_call(ML99_right, x)
| The right value `x`.
#define | ML99_isLeft(either) ML99_call(ML99_isLeft, either)
| `ML99_true()` if `either` contains a left value, otherwise `ML99_false()`.
#define | ML99_isRight(either) ML99_call(ML99_isRight, either)
| The inverse of ML99_isLeft.
#define | ML99_eitherEq(cmp, either, other) ML99_call(ML99_eitherEq, cmp, either, other)
| Tests `either` and `other` for equality.
#define | ML99_unwrapLeft(either) ML99_call(ML99_unwrapLeft, either)
| Returns the left value on `ML99_left(x)` or emits a fatal error on `ML99_right(y)`.
#define | ML99_unwrapRight(either) ML99_call(ML99_unwrapRight, either)
| The inverse of ML99_unwrapLeft.
#define | ML99_LEFT(x) ML99_CHOICE(left, x)
#define | ML99_RIGHT(x) ML99_CHOICE(right, x)
#define | ML99_IS_LEFT(either) ML99_PRIV_IS_LEFT(either)
#define | ML99_IS_RIGHT(either) ML99_NOT(ML99_IS_LEFT(either))

## Detailed Description

A choice type with two cases.

## Macro Definition Documentation

## ML99_eitherEq

#define ML99_eitherEq | ( |  | cmp,
|  |  | either,
|  |  | other
| ) |  | ML99_call(ML99_eitherEq, cmp, either, other)

Tests `either` and `other` 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)))
either.h
A choice type with two cases.
ML99_right
#define ML99_right(x)
The right value x.
Definition either.h:23
ML99_left
#define ML99_left(x)
The left value x.
Definition either.h:18
ML99_eitherEq
#define ML99_eitherEq(cmp, either, other)
Tests either and other for equality.
Definition either.h:78
v
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145
nat.h
Natural numbers: [0; 255].
ML99_natEq
#define ML99_natEq(x, y)
Definition nat.h:112

## ML99_isLeft

#define ML99_isLeft | ( |  | either | ) | ML99_call(ML99_isLeft, either)

`ML99_true()` if `either` contains a left value, otherwise `ML99_false()`.

# Examples

#include <metalang99/either.h>
// 1
ML99_isLeft(ML99_left(v(123)))
// 0
ML99_isLeft(ML99_right(v(123)))
ML99_isLeft
#define ML99_isLeft(either)
ML99_true() if either contains a left value, otherwise ML99_false().
Definition either.h:40

## ML99_isRight

#define ML99_isRight | ( |  | either | ) | ML99_call(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_isRight
#define ML99_isRight(either)
The inverse of ML99_isLeft.
Definition either.h:57

## ML99_unwrapLeft

#define ML99_unwrapLeft | ( |  | either | ) | ML99_call(ML99_unwrapLeft, either)

Returns the left value on `ML99_left(x)` or emits a fatal error on `ML99_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_unwrapLeft
#define ML99_unwrapLeft(either)
Returns the left value on ML99_left(x) or emits a fatal error on ML99_right(y).
Definition either.h:95

## ML99_unwrapRight

#define ML99_unwrapRight | ( |  | either | ) | ML99_call(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_unwrapRight
#define ML99_unwrapRight(either)
The inverse of ML99_unwrapLeft.
Definition either.h:112