2 ms·
Kotlin has type aliases. This means you can write something like: typealias Cent = Int and then use a type Cent just like you can an Int, with multiplicati
by aembleton 4y ago
Kotlin has type aliases. This means you can write something like:
typealias Cent = Int
and then use a type Cent just like you can an Int, with multiplication and everything else. More info: https://kotlinlang.org/docs/type-aliases.html https://kotlinlang.org/docs/type-aliases.html
- dragonwriter 4y agoYes, you can, but you shouldn’t to solve this problem, because typealiases aren’t new types, just–as the name suggests–aliases, so anything aliased to Int is interchangeable with Int and everything else aliased that way, so you still have exactly the same problem. Also, cents * cents shouldn’t be cents (though cents * unitless ints should be).
- aembleton 4y agoGood point, it doesn't solve the problem
- Akronymus 4y agoThat's not quite the same thing, as in f# a unit of measure actually makes not interchangable. While a type alias, afaik, literally is just an alias, without preventing you to do something like that: typealias Cent = Int typealias Euro = Int SomeEuro = SomeCent In f#, measures aren't bound to any specific numeric type either.