Manuscript Documentation
v2026.12.0

@std/core.ms#

Error, Optional, Result, Equal, Comparable, and Hashable are prelude declarations; explicit imports of them are rejected.

Import other names with import Name from "@std/core.ms".

Clonable Interface#

A type whose values can be duplicated. Plain data is Clonable; resource handles, natives without a clone of their own (a Regex, a Pipe), function values, and any record, alternative or collection holding one of those are not. There is nothing to implement: the bound T Clonable makes value.clone() available on a type parameter.

Manuscript
interface Clonable {
    fn clone() Self
}

Clonable.clone#

Returns an independent deep copy of this value.

Manuscript
fn clone() Self

Closeable Interface#

A resource that can be closed. A binding that holds one is closed when its scope ends, on every exit.

The implicit close behaves like value.close()?: a failed close becomes the function’s error, after the other bindings of the scopes it leaves have closed. A failed close is a fault where the function cannot return an Error, or where the resource sits inside a holder (a record, list or temporary). If the scope is already returning an error, that error is kept and the close error is dropped. Call close() yourself to handle the failure; the binding is then consumed.

Manuscript
interface Closeable {
    move fn close() Result[Void, Error]
}

Closeable.close#

Releases the resource. The compiler calls this on every scope exit, including returns, expected errors, faults and cancellation. A type whose release cannot fail returns ok().

Manuscript
move fn close() Result[Void, Error]

Comparable Interface#

A type with a total order; compare agrees with equals when both are implemented.

Manuscript
interface Comparable {
    fn compare(other Self) Int
}

Comparable.compare#

Orders this value against another of the same type: negative when it sorts before, zero when neither sorts first, positive when it sorts after.

Manuscript
fn compare(other Self) Int

Data Interface#

A type whose values are plain data: no resource, function, interface value or runtime handle anywhere inside. Bytes cross a boundary only as data, so json.parse, json.stringify and the typed JSON stream codecs require T Data. Promises and pipes do not require this bound.

There is nothing to implement. Records and alternatives are Data when every field is. Among the collections, a List is Data when its element is, and a Map[String, T] is Data when T is (it is a JSON object). A Set, a Map with another key type, a Closeable type and an opaque type are never Data. JsonValue is Data by declaration, so a dynamic JSON object travels as a JsonValue.

Manuscript
interface Data {
}

Equal Interface#

A type that can be compared for equality. Built-in data keeps its value semantics; an explicit implementation chooses what counts as the same value.

Manuscript
interface Equal {
    fn equals(other Self) Bool
}

Equal.equals#

Compares this value with another value of the same type.

Manuscript
fn equals(other Self) Bool

Error Type#

An expected failure as a plain value: a message, a short code callers can branch on, and string details. Build one like any record: Error("no such file", kind: "ENOENT", details: {"path": path}). T! is Result[T, Error].

Manuscript
type Error {
    message String
    kind String? = null
    details Map[String, String] = Map[String, String]()
}

Error.details#

Extra facts about the failure, such as the path or operation, keyed by name.

Manuscript
details Map[String, String] = Map[String, String]()

Error.kind#

A short code for what went wrong, or null when no code fits. The kind itself never allocates when it is a literal or at most 15 bytes. The standard library reports POSIX errno names (EAUTH is Manuscript’s own), so error.kind == "ENOENT" means the same on every platform:

  • EINVAL: caller input is invalid
  • EBADMSG: input data is malformed
  • EOVERFLOW: a limit was exceeded
  • ERANGE: a value or index is out of range
  • ENOENT: not found
  • EEXIST: already exists
  • ENOTEMPTY: directory not empty
  • EACCES: permission denied
  • ENOTSUP: unsupported
  • ENOTTY: not a terminal
  • EBADF: resource closed
  • EIO: a task, process or peer ended abnormally
  • EAGAIN: service unavailable
  • EBUSY: resource busy
  • ENAMETOOLONG: a file name or path is too long
  • ELOOP: too many symbolic links
  • ENOSPC: no space left on the device
  • EROFS: the file system is read-only
  • EXDEV: the paths are on different devices
  • EMFILE: too many open files
  • ETIMEDOUT: a deadline expired
  • ECANCELED: cancelled
  • EAUTH: authentication failed

Your own code uses its own prefix, such as "EQUOTA".

Manuscript
kind String? = null

Error.message#

Human-readable description of the failure.

Manuscript
message String

Hashable Interface#

A type with a stable hash that is consistent with its Equal implementation.

Manuscript
interface Hashable {
    fn hash() Int
}

Hashable.hash#

Returns a stable hash consistent with equals for the same value.

Manuscript
fn hash() Int

Iterator Interface#

A source of items that for walks: each next returns the following item, or null once exhausted. for item in source: calls next until null. A variable or field path advances in place and keeps its final state, while any other expression is held by the loop alone. next should keep returning null after the end. The item is a borrow: it stays valid, and the iterator stays unchanged, until the loop body ends. Clone it to keep it.

Manuscript
interface Iterator[T] {
    var fn next() T?
}

Iterator.next#

Returns the next item, or null when no items remain. The item borrows from the iterator (an iterator over a container borrows from the container instead).

Manuscript
var fn next() T?

Optional Enum#

Represents a value that may be absent: a T or null; a plain T converts where a T? is expected.

Manuscript
enum Optional[T] {
    some(value T)
    null
}

Optional.null#

An absent value with no payload; no T needs to be constructed.

Manuscript
null

Optional.some#

A present payload, retained by reference when T is mutable.

Manuscript
some(value T)

Optional.some.value#

The contained value; unwrap and matching return this original payload.

Manuscript
value T

Optional.clone#

An Optional copies its payload; null stays null.

Manuscript
// Receiver: T?; T Clonable
fn clone() T?

Result Enum#

Holds either a successful value (ok) or an expected failure (error).

Manuscript
enum Result[T, E] {
    ok(value T)
    error(cause E)
}

Result.error#

An expected failure value; it is distinct from faults and cancellation.

Manuscript
error(cause E)

Result.ok#

A successful result, retaining its payload without a deep copy.

Manuscript
ok(value T)

Result.error.cause#

The original domain error, retained through compatible Result propagation.

Manuscript
cause E

Result.ok.value#

The successful value returned by unwrap, matching, or propagation.

Manuscript
value T

Result.and_then#

Calls transform only on success and returns the Result it produces; an error passes through. The error type stays the same.

Manuscript
move fn and_then[U](transform fn(move T) Result[U, E]) Result[U, E]

Result.err#

Returns the error payload; check is_error() first, because a successful result raises a fault.

Manuscript
fn err() E

Result.get#

Returns the successful payload; an error raises a fault, so use it only when failure is a bug. Prefer ?, if value := result: or get_or(default).

Manuscript
fn get() T

Result.get_or#

Returns the successful payload, or default when this is an error. The default is always evaluated; use get_or_else when it costs work.

Manuscript
move fn get_or(move default T) T

Result.get_or_else#

Returns the successful payload; for an error, calls create once with that error and returns its value.

Manuscript
move fn get_or_else(create fn(move E) T) T

Result.is_error#

Reports whether this result contains an expected error.

Manuscript
fn is_error() Bool

Result.is_ok#

Reports whether this result contains a successful value.

Manuscript
fn is_ok() Bool

Result.map#

Transforms only a successful payload, preserving an error unchanged.

Manuscript
move fn map[U](transform fn(move T) U) Result[U, E]

Result.map_error#

Transforms only an error, preserving a successful payload unchanged.

Manuscript
move fn map_error[F](transform fn(move E) F) Result[T, F]

Result.or_else#

Returns this result when it is successful; for an error, calls create once with that error and returns the Result it produces.

Manuscript
move fn or_else(create fn(move E) Result[T, E]) Result[T, E]

Result.to_optional#

Returns some with the original success payload, or null for an error.

Manuscript
move fn to_optional() T?

Stringable Interface#

A type with its own text form. f"{value}", print and a container’s text use to_string when a record or alternative has one; the operation must return a String. Every standard type with a text form meets this interface the same way, by declaring to_string.

Manuscript
interface Stringable {
    fn to_string() String
}

Stringable.to_string#

Returns this value as text.

Manuscript
fn to_string() String

Writable Interface#

Data that a write accepts as either text or raw bytes. String and Bytes both implement it, so write_file(path, "text") and write_file(path, bytes) call the same function. Text is written as its UTF-8 encoding.

Manuscript
interface Writable {
    fn as_bytes() Bytes
}

Writable.as_bytes#

The bytes to write, as a new value the writer may keep.

Manuscript
fn as_bytes() Bytes

join_errors Function#

Combines errors into one error whose message holds theirs, one per line, and whose count detail is how many there were. Returns null when the list is empty.

Manuscript
fn join_errors(errors List[Error]) Error? { ... }

ok_or Function#

Returns ok with the value, or error with cause when value is null. The cause is built before the call whether or not it is used.

Manuscript
fn ok_or[T, E](move value T? = null, move cause E) Result[T, E] { ... }

panic Function#

Raises a programming fault with the supplied message and stops the current operation.

Manuscript
fn panic(message String) Never { ... }

print Function#

Writes value as text, followed by end (a newline unless given), to standard output. print(chunk, end: "") streams text without a newline. A type that declares its own to_string() prints that text, also when nested in a list or map; other records print structurally. print returns Void. Output to a terminal is flushed at each newline. Output to a pipe or file is flushed when the program blocks or exits, so a line printed before a wait is visible while it waits. Use stdout() from @std/io/io.ms to write text with no appended newline, or stdout_bytes() for bytes.

Manuscript
print(f"total: {total}")
print(order)
Manuscript
fn print[T](value T, end String = "\n") Void { ... }

wrap_error Function#

Returns a copy of cause with context in front of its message, as in error(wrap_error("read config", cause)). The kind and details are kept, and the original message is added to details["cause"].

Manuscript
fn wrap_error(context String, cause Error) Error { ... }