Hullaballoonatic
07/02/2019, 9:52 PMwhere
syntax
current:
class Foo<A, B>(val a: A, val b: B) where A: Bar, A: Baz
proposed:
class Foo<A: Bar & Baz, B>(val a: A, val b: B)
not like &
is getting any use in Kotlin anyhow...or
functionality, similar to how it is used in javascript.
A quick example of how that would be really nice:
fun <N: Byte | Int | Float | Double> areaByMetres(length: N, width: N) = Area(length.toDouble().metre, width.toDouble().metre)
To allow for areaByMetres
to accept any number type that can be safely cast up to Double for either of its params would take 8 more declarations of the function. If we were doing this for volume, then it would take 27 more. Yikes!
Of course allowing for multiple possible types has a lot more ramifications, and I imagine would be very difficult to add to a strongly typed language, and is arguably no longer strongly typed.kevinmost
07/02/2019, 9:57 PMkarelpeeters
07/02/2019, 9:58 PMHullaballoonatic
07/02/2019, 9:58 PM