Numeric — Numeric Types

Part of the std module. Available via import std.

Refined numeric types built on wrap types with validation constraints.

Integer Subtypes

Natural

wrap Natural: Integer

valid Natural
  unwrap >= 0

Non-negative integers: 0, 1, 2, 3, …​

Positive

wrap Positive: Natural

valid Positive
  unwrap as Integer != 0

Strictly positive integers: 1, 2, 3, …​ Wraps Natural, adding the constraint that the value is non-zero.

Negative

wrap Negative: Integer

valid Negative
  unwrap <= 0

Non-positive integers: 0, -1, -2, -3, …​

Port Types

Port

wrap Port: Natural

valid Port
  unwrap as Integer <= 65535

A network port number (0-65535).

WellKnownPort

wrap WellKnownPort: Port

valid WellKnownPort
  unwrap as Integer <= 1023

Ports in the well-known range (0-1023).

RegisteredPort

wrap RegisteredPort: Port

valid RegisteredPort
  unwrap as Integer >= 1024
  unwrap as Integer <= 49151

Ports in the registered range (1024-49151).

EphemeralPort

wrap EphemeralPort: Port

valid EphemeralPort
  unwrap as Integer >= 49152
  unwrap as Integer <= 65535

Ports in the ephemeral range (49152-65535).

PortType

union PortType
  wellKnown
  registered
  ephemeral

Enumeration of port range categories.

Functions

toPort

toPort: pt:PortType. Type
  match pt:
    wellKnown: WellKnownPort
    registered: RegisteredPort
    ephemeral: EphemeralPort

Maps a PortType to its corresponding port type.

fib

fib: n:Integer. Integer
  match n:
    0: 0
    1: 1
    _: fib (n - 1) + fib (n - 2)

Fibonacci sequence. Included as a standard recursive function example.