I <saw a claim> that Kotlin uses nominal (as oppos...
# compiler
p
I saw a claim that Kotlin uses nominal (as opposed to structural) type compatibility and equivalence. I have a hunch this is true for JVM but maybe not for Kotlin/Native or Kotlin/JS. Would the claim be correct or is my hunch a good one?
y
AFAIK, K/JVM and K/Native are nominal, while K/JS is i guess mostly nominal except when you use a
dynamic
type
p
You might be right. I saw that Swift uses structural type checking which I understand allows for independent module deployability, a good thing. I read that @abreslav researched other languages being designed in the timeframe of Kotlin's birth and suspected Swift might be one them, for the context of Kotlin/Native.
y
Also, while Kotlin doesn't have structural typing, it can kind of emulate it well with multiple receivers which are coming soon. As in you define an interface with the typing and then you require an implemented of that interface for a specific type as one of your receivers. It isn't really structural typing but it kind of looks like it which IMO is good enough. I suspect though that someone will come up with a compiler plugin at some point that automatically generates structural definitions of most functions and implements them automatically, which actually isn't really rocket science once we have multiple receivers
p
Very cool! Is coming soon the same as 1.5?
y
I'm actually not entirely sure. I'm assuming that it'll be in 1.5 at least in an experimental state, but the details are a bit hazy right now
For the structural typing bit, take a look at the type classes/extension interfaces section of the multiple receiver issue: https://youtrack.jetbrains.com/issue/KT-10468 but yeah there isn't any confirmation anywhere that multiple receivers will be coming in 1.5. However I do suspect that at least we'll see that prototype in 1.5 and so a lot of the community will just use it since it is immensely useful
🙏 1