No matching definitions.

tur/nat

stdlib/nat.tur

natural numbers as a sum: Zero and Succ.

Nat encodes a number at the type level as a phantom type. True compile-time length safety is deferred to a future dependent-types phase.

Since: Phase G4

defdata

Nat

(defdata Nat (Zero) (Succ Nat))
defn

nat-zero

(nat-zero :Nat)

construct the Zero natural number.

A (Nat) value representing zero.

(nat-zero)  ; => Zero

Since: Phase G4

defn

nat-succ

(nat-succ [n :Nat] :Nat)

construct the successor of a natural number.

nthe predecessor (Nat) value

A (Nat) value representing n+1.

(nat-succ (nat-zero))  ; => Succ(Zero)

Since: Phase G4

defn

nat-to-int

(nat-to-int [n :Nat] :int)

convert a type-level Nat to a runtime integer.

nthe (Nat) value to convert

The integer representation of n.

(nat-to-int (Succ (Succ (Zero))))  ; => 2

Since: Phase G4

defn

nat-add

(nat-add [a :Nat b :Nat] :Nat)

add two type-level Nat values.

afirst (Nat) value
bsecond (Nat) value

A (Nat) representing a + b.

(nat-to-int (nat-add (Succ (Zero)) (Succ (Succ (Zero)))))  ; => 3

Since: Phase G4