.nib std
nib 0.3.0

type

Primitive types

Int, Float, Bool, String, (), and the unnamed shapes built from them — records and tuples.

These types have literals and operators; nothing converts between them implicitly. Float's conversions and rounding are in Float.

Int, Float and Bool

Int is a whole number, written 7 or -3, with + - * / % (division truncates; / and % raise Err.DivisionByZero unless the divisor is a non-zero literal, so n / 2 raises nothing). Float is written with a decimal point, 1.5 or -0.25, and its arithmetic has its own dotted operators, +. -. *. /., as in OCaml: 1.5 + 2.5 is a type error, and 1.5 +. 2.5 is 4.0. Nothing converts between the two implicitly; Float has of_int and to_int. Bool is true or false, combined with && and ||.

let n = 17;
(n / 5, n % 5, n * 2 - 1, n > 10 && n < 20)
(3, 2, 33, true)
let x = 1.5;
(x *. 2.0 -. 0.5, -.x, Float.of_int(3) /. 2.0)
(2.5, -1.5, 1.5)

String

Text, written "…". ++ joins two strings, and {name} inside a literal splices a value in, which is also how a number becomes text. The functions are in String.

let who = "ada";
let n = 3;
"hello, " ++ who ++ " — you have {n} messages"
hello, ada — you have 3 messages

()

The unit type: one value, also written (). A function that is run for its effect, like Io.Print's println, answers it.

Records

#{ name: "ada", age: 36 } is a record: named fields, read with .name. A record needs no declaration; when a shape deserves a name, declare it with data and the same fields.

let p = #{ name: "ada", age: 36 };
"{p.name} is {p.age}"
ada is 36

Tuples

(1, "one") is a tuple: a value with positions and no names. Its type is inferred, never written, and there is no .0 to take it apart — reach for a record whenever the parts are worth naming.

(1, "one")
(1, "one")

Comparing

== and != compare any two values of the same type structurally — numbers, strings, records, tuples, Vecs, sums. <, <=, > and >= order numbers (Int or Float); strings have no ordering operator today. A Bytes buffer is the exception to equality: it is mutable, so it has none at all.

(#{ a: 1, b: #[2] } == #{ a: 1, b: #[2] }, 1.5 < 2.5)
(true, true)