5 ms·
Gonna shoutout F#'s unit-of-measure types > It's "small" but rather important not to mix units! With unit of measure, it's possible to easily/simply create ty
by dharmaturtle 5y ago
Gonna shoutout F#'s unit-of-measure types
> It's "small" but rather important not to mix units!
With unit of measure, it's possible to easily/simply create types like CustomerId, which is actually a Guid/Int under the covers. Means you can't pass a CustomerId to something that expects an OrderId. These types are erased at compile time, so there's zero effect on runtime performance. It's lovely.
- tadfisher 5y agoSee also: Haskell newtypes and Kotlin value classes (née inline classes).
- sullyj3 5y agoDoes Kotlin have the equivalent of GeneralizedNewTypeDeriving or whatever is required to make math operators work without boilerplate?
- tsimionescu 5y agoOne unexpected aspect of unit-of-measurement types is that they don't generalize well at all to anything more complex than basic arithmetic. For example, it's very hard to create a type-safe library that allows you to compute the dot product of (1m 1Hz) and (1Hz 1m) and get 2m/s, but doesn't allow you to accidentally compute the dot product of (1m 1Hz) with itself.
- deleted 5y ago[deleted]