Metalang99 1.13.3
Full-blown preprocessor metaprogramming
maybe.h
Go to the documentation of this file.
1
6#ifndef ML99_MAYBE_H
7#define ML99_MAYBE_H
8
9#include <metalang99/priv/util.h>
10
11#include <metalang99/bool.h>
12#include <metalang99/choice.h>
13#include <metalang99/ident.h>
14
18#define ML99_just(x) ML99_call(ML99_just, x)
19
23#define ML99_nothing(...) ML99_callUneval(ML99_nothing, )
24
40#define ML99_isJust(maybe) ML99_call(ML99_isJust, maybe)
41
57#define ML99_isNothing(maybe) ML99_call(ML99_isNothing, maybe)
58
78#define ML99_maybeEq(cmp, maybe, other) ML99_call(ML99_maybeEq, cmp, maybe, other)
79
95#define ML99_maybeUnwrap(maybe) ML99_call(ML99_maybeUnwrap, maybe)
96
97#define ML99_JUST(x) ML99_CHOICE(just, x)
98#define ML99_NOTHING(...) ML99_CHOICE(nothing, ~)
99#define ML99_IS_JUST(maybe) ML99_PRIV_IS_JUST(maybe)
100#define ML99_IS_NOTHING(maybe) ML99_NOT(ML99_IS_JUST(maybe))
101
102#ifndef DOXYGEN_IGNORE
103
104#define ML99_just_IMPL(x) v(ML99_JUST(x))
105#define ML99_nothing_IMPL(...) v(ML99_NOTHING())
106
107#define ML99_isJust_IMPL(maybe) v(ML99_IS_JUST(maybe))
108#define ML99_isNothing_IMPL(maybe) v(ML99_IS_NOTHING(maybe))
109
110// ML99_maybeEq_IMPL {
111
112#define ML99_maybeEq_IMPL(cmp, maybe, other) \
113 ML99_matchWithArgs_IMPL(maybe, ML99_PRIV_maybeEq_, cmp, other)
114
115#define ML99_PRIV_maybeEq_just_IMPL(x, cmp, other) \
116 ML99_matchWithArgs_IMPL(other, ML99_PRIV_maybeEq_just_, cmp, x)
117#define ML99_PRIV_maybeEq_nothing_IMPL(_, _cmp, other) v(ML99_IS_NOTHING(other))
118
119#define ML99_PRIV_maybeEq_just_just_IMPL(y, cmp, x) ML99_appl2_IMPL(cmp, x, y)
120#define ML99_PRIV_maybeEq_just_nothing_IMPL ML99_false_IMPL
121// } (ML99_maybeEq_IMPL)
122
123#define ML99_maybeUnwrap_IMPL(maybe) ML99_match_IMPL(maybe, ML99_PRIV_maybeUnwrap_)
124#define ML99_PRIV_maybeUnwrap_just_IMPL(x) v(x)
125#define ML99_PRIV_maybeUnwrap_nothing_IMPL(_) \
126 ML99_fatal(ML99_maybeUnwrap, expected ML99_just but found ML99_nothing)
127
128#define ML99_PRIV_IS_JUST(maybe) ML99_DETECT_IDENT(ML99_PRIV_IS_JUST_, ML99_CHOICE_TAG(maybe))
129#define ML99_PRIV_IS_JUST_just ()
130
131// Arity specifiers {
132
133#define ML99_just_ARITY 1
134#define ML99_nothing_ARITY 1
135#define ML99_isJust_ARITY 1
136#define ML99_isNothing_ARITY 1
137#define ML99_maybeEq_ARITY 3
138#define ML99_maybeUnwrap_ARITY 1
139// } (Arity specifiers)
140
141#endif // DOXYGEN_IGNORE
142
143#endif // ML99_MAYBE_H
Boolean algebra.
Choice types: (tag, ...).
Identifiers: [a-zA-Z0-9_]+.