Scala Language Handling units (measures) Type aliases


Example

type Meter = Double

This simple approach has serious drawbacks for unit handling as every other type that is a Double will be compatible with it:

type Second = Double
var length: Meter = 3
val duration: Second = 1
length = duration
length = 0d

All of the above compiles, so in this case units can only be used for marking input/output types for the readers of the code (only the intent).