<Reddit question>, but curious if anyone knows - w...
# random
r
Reddit question, but curious if anyone knows - why does function declaration use ":" to designate the return type, but lambda syntax uses "->"? Was there some language design reason this was required?
e
honestly the
->
really bugs me in swift and python (typing);
:
is consistently property/function return type in Kotlin
so it is inconsistent with function types, but if they used
:
then we'd have declarations like
Copy code
val callback: (): Unit
and I think that's worse than
->
just for that case
r
It is but - why not
->
for everything then?
e
because in every other use case, it's
: Type
Copy code
class Child(...) -> Parent
is definitely questionable, and function syntax and class declaration (especially with primary constructor) syntax mirror each other
r
A Child doesn't return a Parent; hence, the distinction
a
I think I am with you @Ryan Rolnicki,
:
should still remain for inheritance and type specification for properties and function arguments
->
be used as a return type Although to be fair, the current syntax is not confusing at all. It is easy to pick it up with very little effort
j
: Type
-> code