Home / Docs / Standard library / Prelude

Nat

Release v0.4.0Edition 0.1 and later

A kind of the prelude, in scope in every module. Edition 0.1 and later.

una
pub kind Nat = Int where it >= 0

An Int that is at least zero: an Int flows into Nat where the bound is proved (spec/14 §1, spec/03 §2).

Definition

Int where it >= 0: an Int that is at least zero; an Int becomes a Nat where the checker proves the bound.

See also

abs

Example

src/shop.unauna
module shop

--- The units left on a shelf, which can never be negative.
remaining(stock: Nat, sold: Nat) -> Nat = if sold > stock then 0 else stock - sold

pub main() -> Unit
  uses @console: Console[print]
=
  let left = remaining(12, sold: 5)
  @console.print("{left} left")
  let empty = remaining(3, sold: 5)
  @console.print("{empty} left")

una run . prints:

Output
7 left
0 left

Specification

Generated from the standard modules of una v0.4.0 (docs/std/listing.json, which is not part of the specification). The specification governs: spec/14 §1.