3 ms·
Type alias is a poor alternative for true primitive types. Like (pseudo code): primitive Dollar: Decimal // no mixing with euros primitive Meter: Doubl
by dep_b 8y ago
Type alias is a poor alternative for true primitive types. Like (pseudo code):
primitive Dollar: Decimal // no mixing with euros
primitive Meter: Double // no confusion with miles
You can do the same in Swift with typealias _but_ it will happily accept you passing in Euro where Dollar is declared because they’re both Decimals. This doesn’t happen in languages like F#.
- slavapestov 8y agoYou can define a struct with a single field of type Double.
- dep_b 8y agoTrue. I think there was a Money cocoapod that used your trick. But you can’t do anything with them you would normally do with the base type unless you add a ton of logic. Also in F# you get the type Meter/Hour if you divide Meters by Hours. Which multiplied by an Hour value gives you the distance traveled at that speed in that time.