Units
trait Unit
Implemented by UnitDefinition, TimeUnit, DataUnit, UnitDefinition, SIPrefix, SIUnit, UnitDefinition.
Required methods
An implementor writes these.
function measureKind
measureKind(measure: Measure) -> Atom
function measureSymbol
measureSymbol(measure: Measure) -> String
function measureFactor
measureFactor(measure: Measure) -> Float
record UnitDefinition
Runtime-defined units are used for prefixes and units derived by arithmetic.
Fields
Implements Unit.
Methods
Defined in other modules
record Measure
A Measure is shared by every unit module. canonical stores the value in that dimension's base unit; its Unit controls its display.
Fields
canonicalFloatvalueFloatunitUnitDefinition
Methods
kind
kind : Atom
scale
scale(multiplier: Number) -> Measure
Formatting into a target display unit deliberately has NO prelude clause. A unit module (Units.SI, Units.Data, ...) supplies to(String, in:) for the units it owns, and reaching one requires importing it. A catch-all here would answer None for an un-imported module instead — a silently empty Optional in place of "you need using Units.SI".
^
^(exponent: Number) -> Measure
Raising a measure preserves its display unit while applying the power to its canonical value, display value, and conversion factor. The current Unit trait represents a dimension as one Atom, so the dimension remains the base kind; the notation records the derived unit (for example s^2).
convertTo
convertTo(unit: Unit) -> Result<Measure, String>
Convert through the Unit trait so units from opt-in modules (SI, Data, and future domains) remain interchangeable with prelude time units.
Defined in other modules
record Duration
Duration is an elapsed span used by Time, Date, and DateTime. A time Measure is deliberately not a Duration: 5.sec describes a measurement.
Fields
secondsFloat
type TimeUnit
Variants
NanosecondMicrosecondMillisecondSecondMinuteHourDayWeek
Implements Unit.
Methods
extends Integer
More methods of Integer, added by this module.
nanosecond
nanosecond : Measure
microsecond
microsecond : Measure
millisecond
millisecond : Measure
timeMeasure
timeMeasure(unit: TimeUnit) -> Measure
extends Float
More methods of Float, added by this module.
nanosecond
nanosecond : Measure
microsecond
microsecond : Measure
millisecond
millisecond : Measure
timeMeasure
timeMeasure(unit: TimeUnit) -> Measure
module Units
The time units are prelude-global, because every unit module measures against the same dimensions — Units.SI defines Watt * Hour with the Hour declared above, and future domains do the same. That makes Hour correct but not obviously located, so the same constructors are reachable under Units too, for call sites that would rather name where a unit comes from. These are aliases, not copies: each binds the identical constructor, so Units.Hour and Hour match the same patterns and compare equal.