Is there any way of binding (instead of defining) possibly recursive functions? For example:
type F = fn(i32) -> i32;
// equivalent to |x| (x+1)*2
fn f: F = composite(add_by(1), mult_by(2));
// equivalent to |x| if x > 100 then {x} else {g(x*2)}
// note the recursion
fn g: F = branch(greater_than(100), identity, composite(mult_by(2), g));
The recursion I am trying to achieve is NOT of closure in general (asked here), which is impossible without hacks, but simply of a normal function with nicer syntax (both type signature and definition).
This could be helpful when type F
is complicated and supposed to be used abstractly, e.g.
type Parser<T> = fn(&str) -> Option<(T, &str)>