Would rust consider absorbing this feature seen in Kotlin: a syntactic shortcut for single-expression functions with an inferred return type.
e.g. fun addExpr(first: Int, second: Int) = first + second
I think this syntax is very intuitive: to my mind it is inspired by haskell and I independently implemented it in my rust-inspired pet-language before I knew kotlin did this.
I think it would also streamline writing some simple constructors:-
fn make_foo(a:..,b:...)= Foo{ x: .... , y: .. , z: ... }
.. and it would be nice to drop a nesting level in functions which are just one 'match' ...
fn foo(a:...) =match a{ ...
}
(maybe you could kill 2 birds with '1.5 stones' and have a special case =match{ }
that matches on the argument type directly)
I gather some assistance is also requested for complex iterator return signatures.
The appeal is that the body of the function is clearly visible in the same line as the inputs, and in many cases -simple math helpers.. think of things like min/max
, clamp
, lerp
etc- , the function is sometimes simpler than the type signature/bounds.
I do like rusts setup most of the time, but that doesn't mean there aren't other cases where different behaviour isn't useful. This reminds me of a discussion over what features a tool needed..
"we use features a/b/c 90% of the time , features d/e/f 10% of the time"
You might then mistakenly assume d/e/f are extraneous, but without them those 10% of use cases end up taking 10x as long, so their presence actually nearly doubles productivity.
I know there are macros, however those have a very different feel, and it's a big syntax change to move code between macros and functions (as jonathan blow explains in his excellent videos, 'code has a maturation cycle').
I know there are objections to whole program inference, but this doesn't go that far.
Do people find it problematic in Kotlin ?
(i would still prefer this [https://github.com/rust-lang/rfcs/pull/2063])
EDIT: see recent reddit thread [https://www.reddit.com/r/rust/comments/6zy8hl/kotlins_coroutines_and_a_comparison_with_rusts/]