OK, the last C monad example:
typedef struct {
char *string;
int value;
} WriterInt;
WriterInt returnWriter(int i)
{
WriterInt r;
r.string = “”;
r.value = i;
return r;
}
WriterInt bind(WriterInt (*f)(int),WriterInt x)
{
WriterInt y = f(x.value);
WriterInt z;
z.value = y.value;
int len = strlen(x.string)+strlen(y.string);
z.string = malloc(len+1);
[...]