I like the idea of making the language more consistent with itself. There is already pattern matching going on when calling a function (fn foo(Pair(x, y): Pair) is a thing), so it would be good if the pattern matching syntax can be uniformly applied.
I have some questions that I hope someone can answer
First, what is the type of f in
let f = |..| { println!("mystery!") };
I suppose I can pass such a f to any function that accepts a callback? So
set_log_handler(f);
will work regardless of how the logging framework in question calls my f?
What if I use f twice:
f(10, 20);
f("Hello!");
Will that also work? I believe that would be the first time you can imagine this kind of syntax in Rust. I guess it shouldn’t work – perhaps the f does actually have a single concrete type and type inference will determine the type when it is first used?
What should the type inference module say if you do
let f = |..| { "first" };
let g = |..| { "second" };
g(f);
Here f is never applied to anything, so it’s difficult to say which type it has. Perhaps that’s okay?
If we have a |x, y, ..| syntax, does this mean that there is a subtype relationship between f and g in
let f = |x, ..| { "at least one argument" };
let g = |x, y, ..| { "at least two arguments" };
Here you would expect to be able to use f everywhere you can use g, which would be the same as saying that f is a subtype of g. This is not necessarily a problem, but I wonder if we have such a hierarchy between function types today?