I'm using them in order to avoid signature clash (...
# random
e
I'm using them in order to avoid signature clash (different return type) would it be possible to do the same as Swift, like here https://stackoverflow.com/a/28079432/1047713 ?
g
JVM includes return type to method signature, but because Java doesn’t, It wouldn’t be possible to support in Kotlin because of interop
e
oh, this is weird.. why has this decision been taken?
g
What kind decision?
to have interop with Java? %)
e
Java not supporting return type to signature, althought JVM includes it
g
because Language != VM 🤷
Language may limit some features of VM if language designers want
e
anyway, I dont really see interop like an abstacle here
Kotlin may extend some java limitations
(like it indeed does with reified btw..)
g
than it would make impossible to call such functions
reified is not extending, it’s just syntactic sugar for Class argument
e
or for example methods using inline classes
g
also this cause a lot of problems with overloading, like which version of the method compiler should select
this is easy on JVM side, because you always specify return type on method call
but in the language it may cause a lot of problems, because you cannot specify return value
g
yes, I do not say that it’s impossible
I just say that it cause many problems with inference and resolution
and all infamous example of recursive type inference in Swift also doesn’t make think good about this decision
t
infamous example of recursive type inference in Swift
Just curious - can you point me to some example of it?
g
Like this:
There is a plenty of similar examples
not sure which of them are exist on each versions, but just an example
also there are recommendations like “use explicit types to make compilation faster”
t
interesting 🤔
g
Right now, the canonical example of problematic code looks something like this:
Copy code
let sum = [1, 2, 3].map { String($0) }.flatMap { Int($0) }.reduce(0, +)
That converts an array of integers into an array of strings, then back to an array of integers, and adds them up.
It’s not the kind of code you’d write in anything serious, of course, but it does illustrate a problem: what might seem like fairly trivial work to us actually takes over 11 seconds to compile on a top of the range MacBook Pro.
I of course don’t want to say that all those problems caused by including return type to signature, I just want to say that resolution and inference is hard, and return type in signature make it even harder
recursive type inference in Swift
Probably “recursive” is bad word, more precisly in those cases we see combinatorial explosion problem with type inference