A simple example for a definition and usage of an unit type:
unit seconds of f32;
unit minutes of f32;
func main() {
let duration = 12<seconds>;
print("The duration is: " + duration); // prints the duration with the unit measurement type
print(toMinutes(duration)); // convert the duration to minutes and print with the unit type
}
func toMinutes(value: unit seconds): unit minutes => value / 60;
You can automaticly convert a unit to another unit by providing conversion rules:
rules for unit seconds
{
from seconds to minutes = seconds / 60;
from minutes to seconds = derive from seconds; // automaticly derive conversion rule. In this case the opposite of seconds: minutes * 60
}