martmists
01/06/2023, 1:10 PMCLOVIS
01/06/2023, 1:13 PMmartmists
01/06/2023, 1:15 PMAny
and do type checks at runtime?CLOVIS
01/06/2023, 1:15 PMmartmists
01/06/2023, 1:19 PMinitializer
method, but it should either be (Int) -> Number
or (Int) -> Complex
. I can't make Complex extend Number as that would cause ambiguity in a lot of the math functions I defined. Since the above isn't possible due to type erasure, I tried making them functional interfaces to have them backed by different types, but this still results in ambiguity according to the compiler, unless I explicitly specify it as NDArray(2, 2, initializer = NumberInitializer { 0 })
rather than NDArray(2, 2) { 0 }
.CLOVIS
01/06/2023, 1:23 PMmartmists
01/06/2023, 1:25 PMCLOVIS
01/06/2023, 1:26 PMComplex
a type you created?martmists
01/06/2023, 1:27 PMCLOVIS
01/06/2023, 1:30 PMsealed interface SomeCommonName {
@JvmInline value class Number(val number: kotlin.Number): SomeCommonName
}
class Complex(…) : SomeCommonName {
// …
}
I'm not mathematician enough to come up with an accurate name for the interface, but you get the ideamartmists
01/06/2023, 1:31 PMCLOVIS
01/06/2023, 1:32 PMmartmists
01/06/2023, 1:32 PMCLOVIS
01/06/2023, 1:32 PMtest(SomeCommonName.Number(…))
That's why people want proper union types
However, now, the signatures don't clash anymore so you can create overloadsJavier
01/06/2023, 6:20 PMmartmists
01/07/2023, 1:25 AMJavier
01/07/2023, 1:32 AMStephan Schröder
01/07/2023, 4:27 PMYou have to explicitly call the constructor@martmists you do have to call the constructor but there's no runtime overhead (unless you put it in a collection) since it's an inline class.
CLOVIS
01/07/2023, 4:28 PMis
checks etc work). It would be the same with proper unions though.CLOVIS
01/07/2023, 4:29 PMStephan Schröder
01/07/2023, 4:29 PM