kex docs Standard Library

Units

trait Unit

Implemented by UnitDefinition, TimeUnit, DataUnit, UnitDefinition, SIPrefix, SIUnit, UnitDefinition.

Required methods

An implementor writes these.

factor

factor : Float

kind

kind : Atom

symbol

symbol : String

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

conversionFactor
Float
dimension
Atom
notation
String

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

canonical
Float
value
Float

Methods

factor

factor : Float

kind

kind : Atom

symbol

symbol : String

to

to(_) -> String

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.

convert

convert(unit: TimeUnit) -> Result<Measure, String>

Short time-unit spelling retained for prelude time measures.

+

+(other: Measure) -> Result<Measure, String>

-

-(other: Measure) -> Result<Measure, String>

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

seconds
Float

type TimeUnit

Variants

  • Nanosecond
  • Microsecond
  • Millisecond
  • Second
  • Minute
  • Hour
  • Day
  • Week

Implements Unit.

Methods

factor Unit

factor(_)

symbol Unit

symbol(_)

extends Integer

More methods of Integer, added by this module.

nanosecond

nanosecond : Measure

microsecond

microsecond : Measure

millisecond

millisecond : Measure

sec

sec : Measure

minute

minute : Measure

hour

hour : Measure

day

day : Measure

week

week : 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

sec

sec : Measure

minute

minute : Measure

hour

hour : Measure

day

day : Measure

week

week : 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.

Nanosecond constant

Microsecond constant

Millisecond constant

Second constant

Minute constant

Hour constant

Day constant

Week constant

Submodules