<@U0AAQKT9Q> how is it any more difficult than `fu...
# language-proposals
b
@ilya.gorbunov how is it any more difficult than
fun Array<*>.myInterfaceFunction() {}
?
i
benleggiero: Do you mean that extension types are the same as extension functions, or that extension types could be somehow implemented with extension functions?
b
I feel like all that needs to happen is that the compiler must know that some generic (or super) type has implemented a function. So:
Copy code
extension Int : Comparable<Int> {
    public operator fun compareTo(other: Int): Int {
        return if (this == other) 0 else if (this < other) -1 else 1
    }
}
would just be:
Copy code
fun Int.compareTo(other: Int): Int {
    return if (this == other) 0 else if (this < other) -1 else 1
}
But then the compiler would allow
Int
to be passed anywhere a
Comparable<Int>
is accepted
i
Int
is already a
Comparable<Int>
, but let's imagine that it's not. What do you expect should happen when you pass
Int
where
Comparable<Int>
is expected? A wrapper that implements the required type to be created?
b
I would just expect the compiler to shrug and the runtime to pass the pointer along
and then
compareTo()
in
Comparable<Int>
would be resolved statically just like a normal extension function
i
The callee who expects an instance of
Comparable<Int>
doesn't know anything about that it should now search for
compareTo
statically instead of invoking it through the interface
b
mmm that's a good point
I suppose that's the advantage Swift has: They wrote their own runtime so they can resolve everything statically