|
|
|
|
|
by innguest
4085 days ago
|
|
I'm not even talking about it at that level, because I don't fully understand it. :) The reason I said that is because I visualize it like this: enum maybeValue { NOTHING, JUST };
typedef enum maybeValue MaybeValue;
struct maybeInt { MaybeValue maybe_value; int integer };
typedef struct maybeInt MaybeInt;
MaybeInt just (int x) { ...; m.maybe_value = JUST; m.integer = x; return m; }
MaybeInt nothing (void) { ...; m.maybe_value = NOTHING; return m; }
MaybeInt chevron (maybeInt a, maybeInt b)
{
if (a.maybe_value == JUST)
if (b.maybe_value == JUST)
just(a.integer + b.integer);
else
nothing();
else
nothing();
}
/* Just 5 >> Nothing >> Just 6 */
chevron(chevron(just(5), nothing()), just(6));
Which is why I said that (>>) ("chevron" above) combines two functions, just() and nothing(). |
|