Logo GenPRES

Units Module

Holds the details of every known unit and creates, compares, looks up and formats units in English or Dutch.

Types and nested modules

Type/Module Description

BSA

Creates the body surface area unit square meter with a given value or with the value 1.

Count

Creates a Count unit with a given value or with the value 1.

Distance

Creates the Distance units meter, centimeter and millimeter with a given value or with the value 1.

Energy

Creates the Energy units calorie and kilocalorie with a given value or with the value 1.

General

Creates a General unit with a name and a value, or with a name and the value 1. The function general, which sets the value 1, raises an ArgumentException for a blank name.

Height

Creates the Height units meter and centimeter with a given value or with the value 1.

InterNational

Creates the international units million IU, IU and milli IU with a given value or with the value 1.

Mass

Creates the Mass units kilogram, gram, milligram, microgram and nanogram with a given value or with the value 1.

Molar

Creates the Molar units mole, millimole and micromole with a given value or with the value 1.

Time

Creates the Time units year, month, week, day, hour, minute and second with a given value or with the value 1.

UnitDetails (Module)

Creates and reads the details of a unit and holds the list with the group, abbreviations, names and synonyms of every known unit.

Volume

Creates the Volume units liter, deciliter, milliliter, microliter and droplet with a given value or with the value 1. A droplet unit holds the number of droplets per milliliter, 20 unless set otherwise.

Weight

Creates the Weight units kilogram and gram with a given value or with the value 1.

Language

Localization

UnitDetails (Type)

Verbal

Functions and values

Function or value Description

apply f u

Full Usage: apply f u

Parameters:
Returns: Unit The unit with the updated value

Apply a function f to the unit value(s) of unit u.

f : BigRational -> BigRational

the function to apply to the unit value

u : Unit

the unit

Returns: Unit

The unit with the updated value

Example

apply (fun n -> n * 2N) (Mass (KiloGram 1N)) = Mass (KiloGram 2N)

eqsUnit u1 u2

Full Usage: eqsUnit u1 u2

Parameters:
    u1 : Unit - The first unit
    u2 : Unit - The second unit

Returns: bool

Check whether unit u1 equals unit u2 irrespective of the unit value.

The unit value is ignored for every unit type EXCEPT General: two general units are equal only when BOTH their name and their value match (e.g. General("x", 1N) does not equal General("x", 2N)). This is deliberate — a general unit's value is part of its identity because there is no canonical base unit to normalise it against.

u1 : Unit

The first unit

u2 : Unit

The second unit

Returns: bool

getDutch lang

Full Usage: getDutch lang

Parameters:
Returns: string

Get the Dutch language string

lang : Language

Returns: string
Example

getDutch { Eng = "abc"; EngPlural = "abcs"; Dut = "def"; DutchPlural = "defs" } = "def"

getEnglish lang

Full Usage: getEnglish lang

Parameters:
Returns: string

Get the English language string

lang : Language

Returns: string
Example

getEnglish { Eng = "abc"; EngPlural = "abcs"; Dut = "def"; DutchPlural = "defs" } = "abc"

getUnitValue u

Full Usage: getUnitValue u

Parameters:
Returns: BigRational option

Get the value of the unit Returns None if no value

u : Unit
Returns: BigRational option

hasGroup u1 u2

Full Usage: hasGroup u1 u2

Parameters:
Returns: bool
u1 : Unit
u2 : Unit
Returns: bool

nUnit _arg1

Full Usage: nUnit _arg1

Parameters:
Returns: RationalX * Unit
_arg1 : Unit
Returns: RationalX * Unit

setUnitValue n

Full Usage: setUnitValue n

Parameters:
Returns: Unit -> Unit

Change the value of a unit to the value n Example: (Mass (KiloGram 1N)) |> setUnitValue 2N = Mass (KiloGram 2N)

n : BigRational
Returns: Unit -> Unit

toString vw uw hasGroup loc verb u

Full Usage: toString vw uw hasGroup loc verb u

Parameters:
    vw : string option - Optional unit value wrapper
    uw : string option - Optional unit wrapper
    hasGroup : bool - When true, includes the unit group in brackets (e.g., "[Mass]"); when false, omits it
    loc : Localization - Localization (English or Dutch)
    verb : Verbal - Verbality (Short or Long)
    u : Unit - The unit to convert to string

Returns: string

Turn a unit u to a string with localization, verbality, and optional group annotation.

vw : string option

Optional unit value wrapper

uw : string option

Optional unit wrapper

hasGroup : bool

When true, includes the unit group in brackets (e.g., "[Mass]"); when false, omits it

loc : Localization

Localization (English or Dutch)

verb : Verbal

Verbality (Short or Long)

u : Unit

The unit to convert to string

Returns: string

toStringDutchLong

Full Usage: toStringDutchLong

Returns: Unit -> string

Turn a unit to a dutch long string with group annotation

Returns: Unit -> string
Example

toStringDutchLong (Time (Minute 1N)) = "minuut[Time]"

toStringDutchShort

Full Usage: toStringDutchShort

Returns: Unit -> string

Turn a unit to a dutch short string with group annotation

Returns: Unit -> string
Example

toStringDutchShort (Time (Minute 1N)) = "min[Time]"

toStringDutchShortWithWrapper vw uw

Full Usage: toStringDutchShortWithWrapper vw uw

Parameters:
    vw : string
    uw : string

Returns: Unit -> string

Turn a unit to a dutch short string with group annotation

vw : string
uw : string
Returns: Unit -> string
Example

toStringDutchShort (Time (Minute 1N)) = "min[Time]"

toStringEngLong

Full Usage: toStringEngLong

Returns: Unit -> string

Turn a unit to an english long string with group annotation

Returns: Unit -> string
Example

toStringEngLong (Time (Day 1N)) = "day[Time]"

toStringEngShort

Full Usage: toStringEngShort

Returns: Unit -> string

Turn a unit to an english short string with group annotation

Returns: Unit -> string
Example

toStringEngShort (Time (Day 1N)) = "day[Time]"

toStringEngShortWithoutGroup

Full Usage: toStringEngShortWithoutGroup

Returns: Unit -> string

Turn a unit to an english short string without group annotation

Returns: Unit -> string
Example

toStringEngShort (Time (Day 1N)) = "day"

tryFind u

Full Usage: tryFind u

Parameters:
Returns: UnitDetails option

Try find unit details in the list of units for unit u Example: tryFind (Mass.kiloGram) = Some { ... }

u : Unit
Returns: UnitDetails option

Type something to start searching.