Here’s another puzzle:
Is it possible in OCaml to define a variable-argument function? For example, can
one define a function f
and values a
and z
such that the following
assertions hold:
assert (f z = 0);
assert (f a z = 1);
assert (f a a z = 2);
assert (f a a a z = 3);
...
Once you’ve got that, how about generalizing it to a variable-argument sum, i.e. define
f
, a
, and z
such that:
assert (f (a i1) (a i2) ... (a ik) z = i1 + i2 + ... + ik);
Or, if you want to eliminate the parens, define an f
, a
, and z
such that:
assert (f a i1 a i2 ... a ik z = i1 + i2 + ... + ik);