kex docs Standard Library

Prelude

The prelude is the part of the standard library every Kex file can see without asking for it. The modules listed below need no import — List, Map, String, IO and the rest are simply there, and so are the traits that make ordinary syntax work on your own types (Enumerable behind .map, Truthyable behind if, Errorable behind .try).

What is NOT here is deliberate, for either of two reasons.

A library that reaches outside the program — the filesystem (FS), regular expressions (Regex), JSON (JSON), the parser combinators (Parsing) — stays one using away, so a file's imports say what it touches.

So does a library most files simply do not need, however pure it is: bit twiddling (Bits), sets and other containers (Data.Set), hashing (Digest), command lines (OptionParser), the sandboxed evaluator (Evaluator). The prelude is a global scope, and every name in it is a name every program has to route around — so the bar is "nearly every file wants this", not "this is useful".

using FS

main do
  IO.printLine(FS.File.read("config.txt").or(""))   # IO is free, FS is asked for
end

Keep this file declarative: each bare using names a sibling stdlib source file, and the toolchain expands them in order when it builds or loads the prelude.

Modules in the prelude

27 module(s), visible in every file with no import.

  • Algebra
  • Binary
  • Blankable
  • Console ANSI terminal styling: colors, text attributes, and cursor control.
  • Enumerable
  • Env
  • Errorable
  • Feed Constructors for Feed.
  • FileHandle
  • IO Console input and output.
  • Kex The running toolchain: which backend, which version, which features.
  • List
  • Map
  • Math Mathematical constants and functions.
  • Number Reading a number out of text without deciding in advance which half of the numeric tower it belongs to.
  • Optional
  • Process Spawning servers, running external commands, and the ambient process operations.
  • Range
  • Stream Constructors for Stream.
  • String Constructors for String values that are built from something other than text — a Unicode codepoint, or raw UTF-8 bytes.
  • System The running process and the machine under it: exiting, and asking what platform this is.
  • Time Building times of day, controlling the clock in tests, and the calendar arithmetic the rest of this file is written on.
  • Test
  • TaggedValidation Diagnostics returned by compile-time validators for tagged literals.
  • Truthyable
  • Type Building and obtaining Type values.
  • Units The time units are prelude-global, because every unit module measures against the same dimensions — Units.SI defines Watt * Hour with the Hour declared above, and future domains do the same. That makes Hour correct but not obviously located, so the same constructors are reachable under Units too, for call sites that would rather name where a unit comes from. These are aliases, not copies: each binds the identical constructor, so Units.Hour and Hour match the same patterns and compare equal.