Language card

silt on one page: the syntax in brief, then every function, constant, type and trait of the standard library. The Language Guide and the reference pages of the standard library say more about each.

A program

import list

type Shape {
  Circle(Int),
  Rect(Int, Int),
}

fn area(s: Shape) -> Int {
  match s {
    Circle(r) -> 3 * r * r
    Rect(w, h) -> w * h
  }
}

fn main() {
  let shapes = [Circle(1), Rect(2, 3)]
  let total = shapes |> list.map { s -> area(s) } |> list.sum
  println("total area: {total}") -- total area: 9
}
open in playground

A file is a module. silt run main.silt runs its fn main(), which returns () or Result((), e), e a type with Display; a main that returns Err(e) (a ? in main) writes error: <e> on stderr and ends the program with status 1. silt run main.silt -- a b gives the program its arguments (io.args()).

Lexical

  • Comments: -- to the end of the line, {- a block, {- nested -} -}.
  • Keywords: as else fn import let match opaque pub return trait type when where. true and false are literals.
  • Names: values, functions, record fields and modules snake_case (a function, a trait method, a field or a module alias starting with a capital is an error); types, traits and variants CamelCase (one starting in lower case is an error); a type variable is a lowercase name (a, e, item).
  • Each statement and declaration starts on a line of its own. Indentation never changes meaning. A statement goes on in the next line after an open bracket or an operator that ends the line, and before a line that starts with an infix operator other than + and - (|> list.map { ... }). A call, ? and a trailing closure stay on the line of what they follow.

Values

KindLiteral
Int, 64-bit, overflow is a runtime error42, -7, 1_000, 0xFF, 0b1010
Float, always finite3.5, 1e3, 2.5e-3
Booltrue, false
String, UTF-8"hi {name}, {n + 1}", escapes \n \r \t \0 \\ \" \{ \} \u{e9}
raw string, no escapes or interpolation"""C:\dir {x}"""
unit()
tuple(1, "a"), one element (1,)
list[1, 2, 3], [0, ..xs], the range 1..10 (inclusive)
map, ordered by key#{ "a": 1, "b": 2 }
set, ordered#[1, 2, 3]
recordUser { name: "A", age: 3 }, User { name, age } (= name: name); a keyword may name a field: e.type, Event { type: t }
record updateuser.{ age: 4 }, user.{ age }
variantSome(1), None, Ok(x), Err(e), Circle(2)
closure{ x -> x * 2 }, { a, b -> a + b }, { (k, v) -> v }, { -> 42 }

Every value is immutable. There is no null, no implicit conversion (Float.from_int(n)), and + is arithmetic only: strings are built by interpolation. Strings, lists and maps are read with module functions (list.get(xs, 0), map.get(m, k)); there is no xs[i].

Bindings and functions

import list

let limit = 10 -- a top-level value, bound once

fn clamp(x: Int, hi: Int) -> Int {
  match {
    x > hi -> hi
    _ -> x
  }
}

fn main() {
  let x = 42
  let x = x + 1 -- shadows: a new binding
  let (a, b) = (1, 2) -- an irrefutable pattern
  let double = { n -> n * 2 }
  let total = [1, 2, 3] |> list.fold(0) { acc, n -> acc + n }
  println("{clamp(x, limit)} {double(a + b)} {total}") -- 10 6 6
}
open in playground
  • fn name(param: Type, ...) -> Ret where a: Trait { body }: the last expression is the value; return v leaves early. Annotations are optional; types are inferred.
  • Functions are top-level only. A local helper is a closure, let f = { n -> ... }, which may call itself by its name.
  • A closure’s parameters are patterns, as a let’s are: a pair is taken apart in place, map.entries(m) |> list.map { (k, v) -> "{k}={v}" }.
  • A closure in the last argument may follow the call: list.map(xs) { x -> x + 1 }.
  • x |> f(y) is f(x, y).
  • An expression before a block’s last has to be (): discard any other value with let _ = ....
  • expr as Type states a type the checker cannot infer: [] as List(Int).

Types

type User { name: String, age: Int }       -- a record
type Shape { Circle(Int), Rect(Int, Int) } -- an enum
type Tree(a) { Leaf, Node(Tree(a), a, Tree(a)) }
type Names = List(String)                   -- an alias
Fn(Int, Int) -> Bool                        -- a function type

A lowercase name in an annotation is a type variable: fn first(xs: List(a)) -> Option(a). A function whose result type is chosen by its caller takes the type as a last parameter, fn parse(s: String, type a), called as json.parse(text, User).

Branching and repeating

match is how silt branches (there is no if), and it must be exhaustive. when ... else, below, leaves a block early.

fn describe(xs: List(Int)) -> String {
  match xs {
    [] -> "empty"
    [x] when x < 0 -> "one negative"
    [0, ..] | [1, ..] -> "starts small"
    [x, ..rest] -> "{x} and {rest}"
  }
}

fn grade(n: Int) -> String {
  match n {
    90..100 -> "A"
    _ -> "B or below"
  }
}

fn main() {
  println(describe([5, 6])) -- 5 and [6]
  println(grade(95)) -- A
}
open in playground
  • Patterns: literals, _, names, variants Some(x) and m.Variant(x), tuples, records User { name, .. }, lists [a, b], [h, ..t], maps #{ "k": v } (with a key: #{} is an error), ranges 1..9, or-patterns a | b, guards p when cond, pins ^x (equal to the existing x), and p as name (matches p and binds the whole value to name: [Token { tok: TEof, .. } as t, ..]; an or-pattern before as is in parentheses, (0 | 1) as bit; behind a bare name, _ or a pattern of only _ and .., (_, _), it is an error). An arm the arms before it leave no value for is a warning.
  • A match without a subject has conditions for patterns (x > 0 -> ...): it takes the first arm whose condition is true, and ends with a _ -> ... arm.
  • when let Some(x) = e else { return d } binds x for the rest of the block; when cond else { ... } checks a condition. The else block must leave: return, panic(...) or a call of a function that returns Never.
  • silt has no loop, while or for. list.each, list.fold and list.fold_until walk a list or a range (1..n), channel.each and channel.fold_until a channel; anything else repeats by a function that calls itself: a top-level fn, or a let closure by its name.
  • A tail call of a function to itself is a jump: it takes no frame, and a call stack shows the function once. A tail call of another function takes no frame either.
  • Any other call takes a frame until it returns. The frames of a program and its tasks may take 128 MiB in all (SILT_FRAME_BUDGET sets another, in MiB), about 700,000 levels of x + sum(rest); a recursion that would take more is the runtime error “stack overflow”. The budget counts the frames only: a recursion that reaches it uses about three times as much memory (about 400 MB at the default).
  • Functions that call themselves (or each other) are checked: every call among them a tail call is “constant stack”; else each call that keeps a frame must pass a part of a parameter (rest of [x, ..rest], a field, what a constructor pattern binds), “depth follows the data”; anything else is an error (E0345) unless the function is written deep fn name(...). A function of such a group that gives () ends with (), return e or a call that gives Never (E0346). A call through a trait is not checked (a json.Decode impl that decodes its own type is one).

Errors

Errors are values: Result(a, e) and Option(a). e? gives the Ok or Some value, or returns the Err or None from the function, whose error type must be the same (? converts nothing). A ? at the end of a pipeline applies to all of it. An error is shown as any value is: the error enums of the standard library as their message ("{e}"), a type of the program by its structure or its Display impl. panic(msg) stops the program. A function declared -> Never (the one place Never is written) never returns either: its body ends in panic, in a call of another such function or in a call of itself that never ends.

Traits

import list

type Temp {
  degrees: Int,
}

trait Describe {
  fn describe(self) -> String
}

trait Describe for Temp {
  fn describe(self) -> String {
    "{self.degrees} degrees"
  }
}

trait Display for Temp {
  fn display(self) -> String {
    "{self.degrees}C"
  }
}

fn all(xs: List(a)) -> List(String) where a: Describe {
  list.map(xs, Describe.describe)
}

fn main() {
  let t = Temp { degrees: 21 }
  println(Describe.describe(t)) -- 21 degrees
  println(all([t])) -- ["21 degrees"]
  println(t) -- 21C
}
open in playground
  • A method is called through its trait, Describe.describe(t); a dot after a value is always a field. A method that makes a value is called on a type: Int.empty(), or a.empty() for a type variable with the bound (where a: Monoid) or a type a parameter.
  • Bounds: where a: Equal + Hash, b: Display. A supertrait: trait Loud: Describe { ... }. A trait may give default bodies and parameters (trait From(a), implemented as trait From(Int) for Temp).
  • An impl is written in the module of its type or of its trait, and is never imported.
  • Built in: Display (by structure, or a written impl), Equal, Hash and Compare (always by structure; an impl of them is an error), Number (Int and Float; it brings Equal, Compare, Hash and Display; a.from_int(0) is the 0 of the type). Functor, Applicative and Monad are traits of type constructors (see Functors). A record compares field by field in declared order, an enum by variant order, then payload.

Modules

import entry              -- the module: entry.parse(line), entry.Entry { ... }
import entry.{ Entry }    -- names alone: Entry { ... }, but no `entry`
import entry as e         -- the module by another name: e.parse(line)

import entry.{ Entry } binds exactly the names it lists, and not entry: to use the module’s functions through entry. and its type by its name, write both lines. An enum imported by name does not bring its variants: list them too, or write Level.Info. Only pub items are seen outside their module. In a package every file directly in src/ is a module, named by its file (see Modules).

Concurrency

task.join([f, g]) runs functions as tasks at the same time and returns when all have returned; the first failure stops the others and is the caller’s. task.background(helpers) { -> ... } runs helper functions while the body runs, stops them when it returns, and gives its value. task.map(xs, n) { x -> ... } calls a function on each item, at most n at a time, and gives the values in order; task.each(ch, n) { v -> ... } does the same for each value of a channel until it is closed and empty; task.first_ok([f, g]) gives the first Ok and stops the rest, or Err of every error in order. These calls return only when the tasks they started have ended, and none gives a handle. task.deadline(d) { -> ... } gives Some of the value, or None when the time passed and the work was stopped. Tasks talk over channels: channel.new(n), channel.send, channel.receive (None once closed and empty), channel.close, channel.select. channel.fold_until(ch, init) { state, msg -> ... } runs an actor: each message gives Continue(next) or Stop(value), and the call gives the value, or the last state when the channel closes (list.fold_until and stream.fold_until take the same steps). I/O inside a task does not block the others. stream.from_fn { ch -> ... } runs a function as the source of a stream, which closes when it returns. task.guard { -> ... } runs a function and gives Ok of its value, or Err(e) for a runtime error raised in it (a task.RuntimeError: message, location, trace).

Tests

A file named *_test.silt holds tests: each fn test_*() runs, and skip_test_* is skipped. In a package, test files go in tests/ or beside the code in src/, and import the package’s modules by name (import entry). A test function returns () or Result((), e), as main does. Assertions are in the test module (test.assert_eq(actual, expected)). silt test runs them all.

Operators, loosest first

||   &&   == !=   < > <= >=   |>   ..   + -   * / %   -x !x   as   f(...) ?   .

All infix operators are left-associative.

Tools

silt run, check, test, fmt, repl (:type <expr>, :doc <name>), lsp, disasm, init, add, remove, update, self-update. -w re-runs run, check, test and disasm when a file changes.

Standard library

Everything but the prelude is reached through its module after import m: list.map(xs, f), io.NotFound(path), time.Weekday. The prelude’s types need no module: Int, Float, Bool, String, (), Bytes, List(a), Map(k, v), Set(a), Channel(a), Fn(a) -> b, Option(a) and Result(a, e); a type of a module is written with it, task.RuntimeError, time.Duration. Each module lists its types, traits and opaque types first, then its functions and constants. A function of a cargo feature is in builds with that feature.

Prelude

type Result(a, e) { Ok(a), Err(e) }
type Option(a) { Some(a), None }
type Step(a) { Stop(a), Continue(a) }
type Bytes  -- opaque
trait Number: Equal + Compare + Hash + Display { fn from_int(n: Int) -> Self }
trait Functor { fn map(xs: Self(a), f: Fn(a) -> b) -> Self(b) }
trait Applicative: Functor { fn pure(x: a) -> Self(a); fn map2(xs: Self(a), ys: Self(b), f: Fn(a, b) -> c) -> Self(c) }
trait Monad: Applicative { fn flat_map(xs: Self(a), f: Fn(a) -> Self(b)) -> Self(b) }
panic(message: a) -> Never where a: Display
print(value: a) -> () where a: Display
println(value: a) -> () where a: Display

io

type IoError { NotFound(String), FolderNotFound(String), PermissionDenied(String), AlreadyExists(String), InvalidInput(String), Interrupted, UnexpectedEof, WriteZero, Other(String) }
io.args() -> List(String)
io.eprint(value: a) -> () where a: Display
io.eprintln(value: a) -> () where a: Display
io.inspect(x: a) -> String
io.read_bytes(path: String) -> Result(Bytes, IoError)
io.read_file(path: String) -> Result(String, IoError)
io.read_line() -> Result(Option(String), IoError)
io.read_stdin() -> Result(String, IoError)
io.read_stdin_bytes() -> Result(Bytes, IoError)
io.stdin_is_terminal() -> Bool
io.write_bytes(path: String, contents: Bytes) -> Result((), IoError)
io.write_file(path: String, contents: String) -> Result((), IoError)

string

string.byte_length(s: String) -> Int
string.char_code(s: String) -> Option(Int)
string.chars(s: String) -> List(String)
string.contains(s: String, sub: String) -> Bool
string.ends_with(s: String, suffix: String) -> Bool
string.from(x: a) -> String where a: Display
string.from_char_code(code: Int) -> Option(String)
string.index_of(s: String, needle: String) -> Option(Int)
string.is_alnum(s: String) -> Bool
string.is_alpha(s: String) -> Bool
string.is_digit(s: String) -> Bool
string.is_empty(s: String) -> Bool
string.is_lower(s: String) -> Bool
string.is_upper(s: String) -> Bool
string.is_whitespace(s: String) -> Bool
string.join(xs: List(String), sep: String) -> String
string.last_index_of(s: String, needle: String) -> Option(Int)
string.left(x: a, width: Int) -> String where a: Display
string.length(s: String) -> Int
string.lines(s: String) -> List(String)
string.pad_left(s: String, width: Int, pad: String) -> String
string.pad_right(s: String, width: Int, pad: String) -> String
string.repeat(s: String, n: Int) -> String
string.replace(s: String, from: String, to: String) -> String
string.right(x: a, width: Int) -> String where a: Display
string.slice(s: String, start: Int, end: Int) -> String
string.split(s: String, separator: String) -> List(String)
string.split_at(s: String, idx: Int) -> Option((String, String))
string.split_once(s: String, separator: String) -> Option((String, String))
string.starts_with(s: String, prefix: String) -> Bool
string.starts_with_at(s: String, offset: Int, prefix: String) -> Bool
string.strip_prefix(s: String, prefix: String) -> Option(String)
string.strip_suffix(s: String, suffix: String) -> Option(String)
string.to_lower(s: String) -> String
string.to_upper(s: String) -> String
string.trim(s: String) -> String
string.trim_end(s: String) -> String
string.trim_start(s: String) -> String

int

type IntError { Empty, InvalidDigit(Int), Overflow, Underflow }
int.abs(n: Int) -> Int
int.bit_and(a: Int, b: Int) -> Int
int.bit_or(a: Int, b: Int) -> Int
int.bit_xor(a: Int, b: Int) -> Int
int.checked_add(a: Int, b: Int) -> Option(Int)
int.checked_div(a: Int, b: Int) -> Option(Int)
int.checked_mul(a: Int, b: Int) -> Option(Int)
int.checked_rem(a: Int, b: Int) -> Option(Int)
int.checked_sub(a: Int, b: Int) -> Option(Int)
int.clamp(x: Int, lo: Int, hi: Int) -> Int
int.max(a: Int, b: Int) -> Int
int.max_value: Int
int.min(a: Int, b: Int) -> Int
int.min_value: Int
int.parse(s: String) -> Result(Int, IntError)
int.parse_radix(s: String, radix: Int) -> Result(Int, IntError)
int.pow(base: Int, exponent: Int) -> Int
int.shift_left(n: Int, count: Int) -> Int
int.shift_right(n: Int, count: Int) -> Int
int.to_radix(n: Int, radix: Int) -> String

float

type FloatError { Empty, InvalidDigit(Int), Overflow, Underflow, NotFinite }
float.abs(f: Float) -> Float
float.ceil(f: Float) -> Float
float.clamp(x: Float, lo: Float, hi: Float) -> Float
float.epsilon: Float
float.floor(f: Float) -> Float
float.format(f: Float, decimals: Int) -> String
float.max(a: Float, b: Float) -> Float
float.max_value: Float
float.min(a: Float, b: Float) -> Float
float.min_positive: Float
float.min_value: Float
float.parse(s: String) -> Result(Float, FloatError)
float.round(f: Float) -> Float
float.to_int(f: Float) -> Int

list

list.all(xs: List(a), f: Fn(a) -> Bool) -> Bool
list.any(xs: List(a), f: Fn(a) -> Bool) -> Bool
list.append(xs: List(a), elem: a) -> List(a)
list.chunks(xs: List(a), n: Int) -> List(List(a))
list.concat(xs: List(a), ys: List(a)) -> List(a)
list.contains(xs: List(a), elem: a) -> Bool where a: Equal
list.drop(xs: List(a), n: Int) -> List(a)
list.drop_while(xs: List(a), f: Fn(a) -> Bool) -> List(a)
list.each(xs: List(a), f: Fn(a) -> ()) -> ()
list.enumerate(xs: List(a)) -> List((Int, a))
list.filter(xs: List(a), f: Fn(a) -> Bool) -> List(a)
list.filter_map(xs: List(a), f: Fn(a) -> Option(b)) -> List(b)
list.find(xs: List(a), f: Fn(a) -> Bool) -> Option(a)
list.find_map(xs: List(a), f: Fn(a) -> Option(b)) -> Option(b)
list.first(xs: List(a)) -> Option(a)
list.flat_map(xs: List(a), f: Fn(a) -> List(b)) -> List(b)
list.flatten(xs: List(List(a))) -> List(a)
list.fold(xs: List(a), init: b, f: Fn(b, a) -> b) -> b
list.fold_until(xs: List(a), init: b, f: Fn(b, a) -> Step(b)) -> b
list.get(xs: List(a), i: Int) -> Option(a)
list.group_by(xs: List(a), f: Fn(a) -> b) -> Map(b, List(a)) where b: Hash
list.index_of(xs: List(a), target: a) -> Option(Int) where a: Equal
list.intersperse(xs: List(a), sep: a) -> List(a)
list.is_empty(xs: List(a)) -> Bool
list.last(xs: List(a)) -> Option(a)
list.length(xs: List(a)) -> Int
list.map(xs: List(a), f: Fn(a) -> b) -> List(b)
list.max_by(xs: List(a), key: Fn(a) -> b) -> Option(a) where b: Compare
list.min_by(xs: List(a), key: Fn(a) -> b) -> Option(a) where b: Compare
list.prepend(xs: List(a), elem: a) -> List(a)
list.product(xs: List(a)) -> a where a: Number
list.remove_at(xs: List(a), index: Int) -> Option(List(a))
list.reverse(xs: List(a)) -> List(a)
list.scan(xs: List(a), init: b, f: Fn(b, a) -> b) -> List(b)
list.sequence(xs: List(m(a))) -> m(List(a)) where m: Applicative
list.set(xs: List(a), index: Int, value: a) -> Option(List(a))
list.sort(xs: List(a)) -> List(a) where a: Compare
list.sort_by(xs: List(a), key: Fn(a) -> b) -> List(a) where b: Compare
list.sort_with(xs: List(a), cmp: Fn(a, a) -> Int) -> List(a)
list.sum(xs: List(a)) -> a where a: Number
list.tail(xs: List(a)) -> List(a)
list.take(xs: List(a), n: Int) -> List(a)
list.take_while(xs: List(a), f: Fn(a) -> Bool) -> List(a)
list.traverse(xs: List(a), f: Fn(a) -> m(b)) -> m(List(b)) where m: Applicative
list.try_each(xs: List(a), f: Fn(a) -> Result((), e)) -> Result((), e)
list.try_each_option(xs: List(a), f: Fn(a) -> Option(())) -> Option(())
list.unfold(seed: a, f: Fn(a) -> Option((b, a))) -> List(b)
list.unique(xs: List(a)) -> List(a) where a: Equal
list.unique_by(xs: List(a), key: Fn(a) -> b) -> List(a) where b: Hash
list.zip(xs: List(a), ys: List(b)) -> List((a, b))

map

map.all(m: Map(a, b), f: Fn(a, b) -> Bool) -> Bool
map.any(m: Map(a, b), f: Fn(a, b) -> Bool) -> Bool
map.contains(m: Map(a, b), key: a) -> Bool where a: Hash
map.each(m: Map(a, b), f: Fn(a, b) -> ()) -> ()
map.entries(m: Map(a, b)) -> List((a, b))
map.filter(m: Map(a, b), f: Fn(a, b) -> Bool) -> Map(a, b)
map.fold(m: Map(a, b), init: c, f: Fn(c, a, b) -> c) -> c
map.from_entries(entries: List((a, b))) -> Map(a, b) where a: Hash
map.get(m: Map(a, b), k: a) -> Option(b) where a: Hash
map.is_empty(m: Map(a, b)) -> Bool
map.keys(m: Map(a, b)) -> List(a)
map.length(m: Map(a, b)) -> Int
map.map(m: Map(a, b), f: Fn(a, b) -> (c, d)) -> Map(c, d) where c: Hash
map.merge(m1: Map(a, b), m2: Map(a, b)) -> Map(a, b) where a: Hash
map.remove(m: Map(a, b), key: a) -> Map(a, b) where a: Hash
map.set(m: Map(a, b), k: a, v: b) -> Map(a, b) where a: Hash
map.update(m: Map(a, b), key: a, default: b, f: Fn(b) -> b) -> Map(a, b) where a: Hash
map.values(m: Map(a, b)) -> List(b)

result

result.flat_map(r: Result(a, b), f: Fn(a) -> Result(c, b)) -> Result(c, b)
result.flatten(r: Result(Result(a, b), b)) -> Result(a, b)
result.is_err(r: Result(a, b)) -> Bool
result.is_ok(r: Result(a, b)) -> Bool
result.map(r: Result(a, b), f: Fn(a) -> c) -> Result(c, b)
result.map_err(r: Result(a, b), f: Fn(b) -> c) -> Result(a, c)
result.to_option(r: Result(a, b)) -> Option(a)
result.unwrap_or(r: Result(a, b), default: a) -> a

option

option.flat_map(opt: Option(a), f: Fn(a) -> Option(b)) -> Option(b)
option.flatten(opt: Option(Option(a))) -> Option(a)
option.is_none(opt: Option(a)) -> Bool
option.is_some(opt: Option(a)) -> Bool
option.map(opt: Option(a), f: Fn(a) -> b) -> Option(b)
option.to_result(opt: Option(a), error: b) -> Result(a, b)
option.unwrap_or(opt: Option(a), default: a) -> a

test

test.assert(condition: Bool) -> ()
test.assert_approx(a: Float, b: Float, tolerance: Float) -> ()
test.assert_eq(left: a, right: a) -> () where a: Equal + Display
test.assert_ne(left: a, right: a) -> () where a: Equal + Display

channel

type ChannelResult(a) { Message(a), Empty, Closed }
type ChannelOp(a) { Recv(Channel(a)), Send(Channel(a), a) }
type Selected(a) { Received(Channel(a), Option(a)), Sent(Channel(a)) }
channel.close(ch: Channel(a)) -> ()
channel.each(ch: Channel(a), f: Fn(a) -> ()) -> ()
channel.fold_until(ch: Channel(a), init: b, f: Fn(b, a) -> Step(b)) -> b
channel.new(capacity: Int) -> Channel(a)
channel.receive(ch: Channel(a)) -> Option(a)
channel.receive_timeout(ch: Channel(a), dur: Duration) -> ChannelResult(a)
channel.select(ops: List(ChannelOp(a))) -> Selected(a)
channel.send(ch: Channel(a), value: a) -> ()
channel.timeout(dur: Duration) -> Channel(a)
channel.try_receive(ch: Channel(a)) -> ChannelResult(a)
channel.try_send(ch: Channel(a), value: a) -> Bool

task

type RuntimeError { message: String, location: String, trace: List(String) }
task.background(helpers: List(Fn() -> ()), body: Fn() -> a) -> a
task.deadline(limit: Duration, work: Fn() -> a) -> Option(a)
task.each(work: Channel(a), at_once: Int, f: Fn(a) -> ()) -> ()
task.first_ok(works: List(Fn() -> Result(a, e))) -> Result(a, List(e))
task.guard(work: Fn() -> a) -> Result(a, RuntimeError)
task.join(pieces: List(Fn() -> ())) -> ()
task.map(xs: List(a), at_once: Int, f: Fn(a) -> b) -> List(b)

regex

type RegexError { InvalidPattern(String, Int), TooBig }
type Regex  -- opaque
regex.captures(text: String, re: Regex) -> Option(List(String))
regex.captures_all(text: String, re: Regex) -> List(List(String))
regex.captures_named(text: String, re: Regex) -> Option(Map(String, String))
regex.compile(pattern: String) -> Result(Regex, RegexError)
regex.escape(text: String) -> String
regex.find(text: String, re: Regex) -> Option(String)
regex.find_all(text: String, re: Regex) -> List(String)
regex.find_all_at(text: String, re: Regex) -> List((Int, Int))
regex.find_at(text: String, re: Regex) -> Option((Int, Int))
regex.is_match(text: String, re: Regex) -> Bool
regex.replace(text: String, re: Regex, replacement: String) -> String
regex.replace_first(text: String, re: Regex, replacement: String) -> String
regex.replace_with(text: String, re: Regex, f: Fn(String) -> String) -> String
regex.split(text: String, re: Regex) -> List(String)

json

type JsonError { Syntax(String, Int, Int, Int), TypeMismatch(String, String, Int, Int, Int), MissingField(String, Int, Int, Int), Other(String, Int, Int, Int) }
type Value { Null, Bool(Bool), Int(Int), Float(Float), String(String), Array(List(Value)), Object(Map(String, Value)) }
trait Encode { fn encode(self) -> Value }
trait Decode { fn decode(value: Value) -> Result(Self, JsonError) }
json.decode(value: Value, type a) -> Result(a, JsonError) where a: Decode
json.encode(value: a) -> Value where a: Encode
json.parse(s: String, type a) -> Result(a, JsonError) where a: Decode
json.parse_with(s: String, keys: Map(String, String), type a) -> Result(a, JsonError) where a: Decode
json.pretty(value: a) -> String where a: Encode
json.stringify(value: a) -> String where a: Encode

toml

type TomlError { Syntax(String, Int, Int, Int), TypeMismatch(String, String, Int, Int, Int), MissingField(String, Int, Int, Int), Other(String, Int, Int, Int), UnknownField(String, List(String), Int, Int, Int) }
toml.parse(s: String, type a) -> Result(a, TomlError) where a: json.Decode
toml.parse_list(s: String, type a) -> Result(List(a), TomlError) where a: json.Decode
toml.parse_map(s: String, type a) -> Result(Map(String, a), TomlError) where a: json.Decode
toml.parse_with(s: String, keys: Map(String, String), type a) -> Result(a, TomlError) where a: json.Decode
toml.pretty(value: a) -> Result(String, TomlError) where a: json.Encode
toml.stringify(value: a) -> Result(String, TomlError) where a: json.Encode

set

set.all(s: Set(a), f: Fn(a) -> Bool) -> Bool
set.any(s: Set(a), f: Fn(a) -> Bool) -> Bool
set.contains(s: Set(a), elem: a) -> Bool where a: Hash
set.difference(a: Set(a), b: Set(a)) -> Set(a)
set.each(s: Set(a), f: Fn(a) -> ()) -> ()
set.filter(s: Set(a), f: Fn(a) -> Bool) -> Set(a)
set.fold(s: Set(a), init: b, f: Fn(b, a) -> b) -> b
set.from_list(xs: List(a)) -> Set(a) where a: Hash
set.insert(s: Set(a), elem: a) -> Set(a) where a: Hash
set.intersection(a: Set(a), b: Set(a)) -> Set(a)
set.is_empty(s: Set(a)) -> Bool
set.is_subset(a: Set(a), b: Set(a)) -> Bool
set.length(s: Set(a)) -> Int
set.map(s: Set(a), f: Fn(a) -> b) -> Set(b) where b: Hash
set.remove(s: Set(a), elem: a) -> Set(a) where a: Hash
set.symmetric_difference(a: Set(a), b: Set(a)) -> Set(a)
set.to_list(s: Set(a)) -> List(a)
set.union(a: Set(a), b: Set(a)) -> Set(a)

math

math.acos(x: Float) -> Float
math.asin(x: Float) -> Float
math.atan(x: Float) -> Float
math.atan2(y: Float, x: Float) -> Float
math.cos(x: Float) -> Float
math.e: Float
math.exp(x: Float) -> Float
math.log(x: Float) -> Float
math.log10(x: Float) -> Float
math.pi: Float
math.pow(base: Float, exponent: Float) -> Float
math.random() -> Float
math.random_int(lo: Int, hi: Int) -> Int
math.sin(x: Float) -> Float
math.sqrt(x: Float) -> Float
math.tan(x: Float) -> Float

time

type Instant { epoch_ns: Int }
type Date { year: Int, month: Int, day: Int }
type Time { hour: Int, minute: Int, second: Int, ns: Int }
type DateTime { date: Date, time: Time }
type Duration { ns: Int }
type Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }
type TimeError { ParseFormat(String), OutOfRange(String), InvalidFormat(String) }
time.add(instant: Instant, duration: Duration) -> Instant
time.add_days(date: Date, days: Int) -> Date
time.add_months(date: Date, months: Int) -> Date
time.date(year: Int, month: Int, day: Int) -> Result(Date, TimeError)
time.datetime(date: Date, time: Time) -> DateTime
time.days_between(from: Date, to: Date) -> Int
time.days_in_month(year: Int, month: Int) -> Int
time.format(datetime: DateTime, pattern: String) -> Result(String, TimeError)
time.format_date(date: Date, pattern: String) -> Result(String, TimeError)
time.hours(n: Int) -> Duration
time.is_leap_year(year: Int) -> Bool
time.micros(n: Int) -> Duration
time.minutes(n: Int) -> Duration
time.ms(n: Int) -> Duration
time.nanos(n: Int) -> Duration
time.now() -> Instant
time.parse(s: String, pattern: String) -> Result(DateTime, TimeError)
time.parse_date(s: String, pattern: String) -> Result(Date, TimeError)
time.parse_instant(s: String, pattern: String) -> Result(Instant, TimeError)
time.seconds(n: Int) -> Duration
time.since(from: Instant, to: Instant) -> Duration
time.sleep(duration: Duration) -> ()
time.time(hour: Int, min: Int, sec: Int) -> Result(Time, TimeError)
time.to_datetime(instant: Instant, offset_minutes: Int) -> DateTime
time.to_instant(datetime: DateTime, offset_minutes: Int) -> Instant
time.today() -> Date
time.weekday(date: Date) -> Weekday

http

type Method { GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS }
type Response { status: Int, body: Bytes, headers: Map(String, String) }
type Request { method: Method, url: Url, headers: Map(String, String), body: Bytes, peer: String }
type HttpError { Connect(String), Tls(String), Timeout, InvalidUrl(String), InvalidResponse(String), ClosedEarly, TooManyRedirects, Other(String) }
http.get(u: Url) -> Result(Response, HttpError)  -- cargo feature `http`
http.request(method: Method, u: Url, body: Bytes, headers: Map(String, String)) -> Result(Response, HttpError)  -- cargo feature `http`
http.request_once(method: Method, u: Url, body: Bytes, headers: Map(String, String)) -> Result(Response, HttpError)  -- cargo feature `http`
http.serve(listener: TcpListener, handler: Fn(Request) -> Response) -> ()  -- cargo feature `http`

fs

type FileStat { size: Int, is_file: Bool, is_dir: Bool, is_symlink: Bool, modified: Option(DateTime), readonly: Bool, mode: Int, accessed: Option(DateTime), created: Option(DateTime) }
fs.copy(from: String, to: String) -> Result((), IoError)
fs.exists(path: String) -> Bool
fs.glob(pattern: String) -> Result(List(String), IoError)
fs.is_dir(path: String) -> Bool
fs.is_file(path: String) -> Bool
fs.is_symlink(path: String) -> Bool
fs.list_dir(path: String) -> Result(List(String), IoError)
fs.mkdir(path: String) -> Result((), IoError)
fs.read_link(path: String) -> Result(String, IoError)
fs.remove(path: String) -> Result((), IoError)
fs.remove_all(path: String) -> Result((), IoError)
fs.rename(from: String, to: String) -> Result((), IoError)
fs.stat(path: String) -> Result(FileStat, IoError)
fs.walk(root: String) -> Result(List(String), IoError)

env

env.get(key: String) -> Option(String)
env.remove(name: String) -> ()
env.set(key: String, value: String) -> ()
env.vars() -> List((String, String))

postgres (cargo feature postgres)

type PostgresError { Connect(String), Tls(String), AuthFailed(String), Query(String, String), TypeMismatch(String, String, String), NoSuchColumn(String), Closed, Timeout, TxnAborted, Other(String) }
type Notification { channel: String, payload: String, pid: Int }
type PgPool  -- opaque
type PgTx  -- opaque
type PgCursor(a)  -- opaque
postgres.close(pool: PgPool) -> ()
postgres.connect(url: String) -> Result(PgPool, PostgresError)
postgres.connect_with(url: String, opts: Map(String, Int)) -> Result(PgPool, PostgresError)
postgres.cursor(tx: PgTx, sql: String, params: p, batch_size: Int, type r) -> Result(PgCursor(r), PostgresError)
postgres.cursor_close(cursor: PgCursor(r)) -> Result((), PostgresError)
postgres.cursor_next(cursor: PgCursor(r)) -> Result(List(r), PostgresError)
postgres.execute(conn: a, sql: String, params: p) -> Result(Int, PostgresError)
postgres.listen(pool: PgPool, channel: String) -> Result(Channel(Notification), PostgresError)
postgres.notify(conn: a, channel: String, payload: String) -> Result((), PostgresError)
postgres.query(conn: a, sql: String, params: p, type r) -> Result(List(r), PostgresError)
postgres.stream(conn: a, sql: String, params: p, type r) -> Result(Channel(Result(r, PostgresError)), PostgresError)
postgres.transact(pool: PgPool, f: Fn(PgTx) -> Result(a, PostgresError)) -> Result(a, PostgresError)

bytes

type BytesError { InvalidUtf8(Int), InvalidHex(String), InvalidBase64(String), ByteOutOfRange(Int) }
bytes.concat(a: Bytes, b: Bytes) -> Bytes
bytes.concat_all(parts: List(Bytes)) -> Bytes
bytes.contains(b: Bytes, needle: Bytes) -> Bool
bytes.empty() -> Bytes
bytes.ends_with(b: Bytes, suffix: Bytes) -> Bool
bytes.from_base64(s: String) -> Result(Bytes, BytesError)
bytes.from_hex(s: String) -> Result(Bytes, BytesError)
bytes.from_list(xs: List(Int)) -> Result(Bytes, BytesError)
bytes.from_string(s: String) -> Bytes
bytes.get(b: Bytes, i: Int) -> Option(Int)
bytes.index_of(b: Bytes, needle: Bytes) -> Option(Int)
bytes.is_empty(b: Bytes) -> Bool
bytes.length(b: Bytes) -> Int
bytes.slice(b: Bytes, start: Int, end: Int) -> Bytes
bytes.split(b: Bytes, sep: Bytes) -> List(Bytes)
bytes.starts_with(b: Bytes, prefix: Bytes) -> Bool
bytes.to_base64(b: Bytes) -> String
bytes.to_hex(b: Bytes) -> String
bytes.to_list(b: Bytes) -> List(Int)
bytes.to_string(b: Bytes) -> Result(String, BytesError)
bytes.to_string_lossy(b: Bytes) -> String

crypto

type CryptoError { InvalidLength(Int), Other(String) }
crypto.blake2b(data: Bytes) -> Bytes
crypto.constant_time_eq(a: Bytes, b: Bytes) -> Bool
crypto.hmac_sha256(key: Bytes, msg: Bytes) -> Bytes
crypto.hmac_sha512(key: Bytes, msg: Bytes) -> Bytes
crypto.md5(data: Bytes) -> Bytes
crypto.random_bytes(n: Int) -> Result(Bytes, CryptoError)
crypto.sha256(data: Bytes) -> Bytes
crypto.sha512(data: Bytes) -> Bytes

url

type UrlError { Invalid(String, Int), InvalidPart(String) }
type Url  -- opaque
url.add_segments(u: Url, segments: List(String)) -> Result(Url, UrlError)
url.decode_form(body: String) -> Result(List((String, String)), UrlError)
url.encode_form(pairs: List((String, String))) -> String
url.escape(text: String) -> String
url.fragment(u: Url) -> String
url.host(u: Url) -> String
url.parse(text: String) -> Result(Url, UrlError)
url.password(u: Url) -> String
url.path(u: Url) -> String
url.port(u: Url) -> Option(Int)
url.query(u: Url) -> List((String, String))
url.query_text(u: Url) -> String
url.resolve(base: Url, reference: String) -> Result(Url, UrlError)
url.scheme(u: Url) -> String
url.segments(u: Url) -> List(String)
url.to_string(u: Url) -> String
url.unescape(text: String) -> Result(String, UrlError)
url.user(u: Url) -> String
url.with_fragment(u: Url, fragment: String) -> Url
url.with_host(u: Url, host: String) -> Result(Url, UrlError)
url.with_password(u: Url, password: String) -> Url
url.with_port(u: Url, port: Option(Int)) -> Result(Url, UrlError)
url.with_query(u: Url, pairs: List((String, String))) -> Url
url.with_scheme(u: Url, scheme: String) -> Result(Url, UrlError)
url.with_segments(u: Url, segments: List(String)) -> Result(Url, UrlError)
url.with_user(u: Url, user: String) -> Url

tcp (cargo feature tcp)

type TcpError { Connect(String), Bind(String), Tls(String), Closed, Timeout, Other(String) }
type TcpListener  -- opaque
type TcpStream  -- opaque
tcp.accept(listener: TcpListener) -> Result(TcpStream, TcpError)
tcp.close(stream: TcpStream) -> ()
tcp.close_listener(listener: TcpListener) -> ()
tcp.connect(addr: String) -> Result(TcpStream, TcpError)
tcp.connect_tls(addr: String, hostname: String) -> Result(TcpStream, TcpError)  -- cargo feature `tcp-tls`
tcp.listen(addr: String) -> Result(TcpListener, TcpError)
tcp.local_port(listener: TcpListener) -> Int
tcp.peer_addr(stream: TcpStream) -> Result(String, TcpError)
tcp.read(stream: TcpStream, max: Int) -> Result(Bytes, TcpError)
tcp.read_exact(stream: TcpStream, n: Int) -> Result(Bytes, TcpError)
tcp.set_nodelay(stream: TcpStream, on: Bool) -> Result((), TcpError)
tcp.tls_server(conn: TcpStream, cert_pem: Bytes, key_pem: Bytes) -> Result(TcpStream, TcpError)  -- cargo feature `tcp-tls`
tcp.tls_server_mtls(conn: TcpStream, cert_pem: Bytes, key_pem: Bytes, client_ca_pem: Bytes) -> Result(TcpStream, TcpError)  -- cargo feature `tcp-tls`
tcp.write(stream: TcpStream, data: Bytes) -> Result((), TcpError)

stream

stream.buffered(ch: Channel(a), n: Int) -> Channel(a)
stream.chunks(ch: Channel(a), n: Int) -> Channel(List(a))
stream.collect(ch: Channel(a)) -> List(a)
stream.concat(chs: List(Channel(a))) -> Channel(a)
stream.dedup(ch: Channel(a)) -> Channel(a) where a: Equal
stream.drop(ch: Channel(a), n: Int) -> Channel(a)
stream.drop_while(ch: Channel(a), pred: Fn(a) -> Bool) -> Channel(a)
stream.enumerate(ch: Channel(a)) -> Channel((Int, a))
stream.file_chunks(path: String, size: Int) -> Channel(Result(Bytes, IoError))
stream.file_lines(path: String) -> Channel(Result(String, IoError))
stream.filter(ch: Channel(a), pred: Fn(a) -> Bool) -> Channel(a)
stream.first(ch: Channel(a)) -> Option(a)
stream.flat_map(ch: Channel(a), f: Fn(a) -> List(b)) -> Channel(b)
stream.fold(ch: Channel(a), init: b, f: Fn(b, a) -> b) -> b
stream.fold_until(ch: Channel(a), init: b, f: Fn(b, a) -> Step(b)) -> b
stream.from_fn(feed: Fn(Channel(a)) -> ()) -> Channel(a)
stream.from_list(xs: List(a)) -> Channel(a)
stream.from_range(lo: Int, hi: Int) -> Channel(Int)
stream.last(ch: Channel(a)) -> Option(a)
stream.length(ch: Channel(a)) -> Int
stream.map(ch: Channel(a), f: Fn(a) -> b) -> Channel(b)
stream.merge(chs: List(Channel(a))) -> Channel(a)
stream.repeat(x: a) -> Channel(a)
stream.scan(ch: Channel(a), init: b, f: Fn(b, a) -> b) -> Channel(b)
stream.stdin_lines() -> Channel(Result(String, IoError))
stream.take(ch: Channel(a), n: Int) -> Channel(a)
stream.take_while(ch: Channel(a), pred: Fn(a) -> Bool) -> Channel(a)
stream.tcp_chunks(stream: TcpStream, size: Int) -> Channel(Result(Bytes, TcpError))  -- cargo feature `tcp`
stream.tcp_lines(stream: TcpStream) -> Channel(Result(String, TcpError))  -- cargo feature `tcp`
stream.unfold(seed: a, f: Fn(a) -> Option((b, a))) -> Channel(b)
stream.write_to_file(ch: Channel(Bytes), path: String) -> Result((), IoError)
stream.write_to_tcp(ch: Channel(Bytes), stream: TcpStream) -> Result((), TcpError)  -- cargo feature `tcp`
stream.zip(a: Channel(a), b: Channel(b)) -> Channel((a, b))

uuid

type UuidError { Invalid(String) }
uuid.is_valid(s: String) -> Bool
uuid.nil() -> String
uuid.parse(s: String) -> Result(String, UuidError)
uuid.v4() -> String
uuid.v7() -> String

process

type Signal { Interrupt, Terminate }
process.exit(code: Int) -> Never
process.stop_signals() -> Channel(Signal)

csv

type CsvError { Syntax(String, Int), TypeMismatch(String, String), MissingField(String), Other(String) }
csv.join_line(fields: List(String)) -> String
csv.parse(text: String, type a) -> Result(List(a), CsvError)
csv.parse_with(text: String, columns: Map(String, String), type a) -> Result(List(a), CsvError)
csv.split_line(line: String) -> Result(List(String), CsvError)
csv.stringify(rows: List(a)) -> String