Finally implemented sum types in pure C99, after a year of experimentation:
datatype(
BinaryTree,
(Leaf, int),
(Node, struct BinaryTree *, int, struct BinaryTree *)
);
Conversation
int sum(const BinaryTree *tree) {
match(*tree) {
of(Leaf, x) {
return *x;
}
of(Node, lhs, x, rhs) {
return sum(*lhs) + *x + sum(*rhs);
}
}
}

