Captain / Documentation

The Captain Language

Contents ↓

Captain is a language for programs that are checked before they run. Its main author is increasingly a machine, and people mainly read its programs, review them and approve their plans; so it favours explicit rules, visible boundaries and one obvious way to write each thing. It has two strengths, and this book treats both as first-class:

  • operations you can approve. A program's effects are known before any of them happen. You can render the plan, approve it by its digest, and run exactly what you approved. Every run is recorded and can be replayed.
  • calculations you can audit. A pure entry has no effects at all. Its numbers are exact decimals, its result is deterministic, and the same inputs always give the same result.

This book is for people who write Captain programs and for people who embed Captain in their own software. It documents the language as the toolchain built from the same source implements it; where something depends on a release, it is on Versions and VM generations.

Part 1. Getting started

  1. What Captain is
  2. Installing Captain
  3. Your first program
  4. The toolchain

Part 2. A tour

  1. An operation, planned, approved and run
  2. A calculation with exact decimals

Part 3. The language

  1. Lexical structure
  2. Modules and names
  3. Procedures and keyword selectors
  4. Integers, booleans and conversion
  5. Text and octets
  6. Symbols, quantities and tagged values
  7. Structs and enums
  8. Option and Result
  9. Lists and shapes
  10. Blocks and control
  11. Types as arguments, and generics
  12. What Captain leaves out, and why
  13. Why Captain is the way it is

Part 4. Effects and safety

  1. Effects
  2. Frontiers
  3. Plans and approval
  4. Secrets, receipts and grants
  5. Determinism, run records and replay
  6. Host policies

Part 5. Numbers

  1. Exact decimals
  2. Division and rounding
  3. Quantities and money

Part 6. The standard library

Part 7. Embedding Captain

Part 8. Where Captain runs

Part 9. Reference

  1. Grammar
  2. Diagnostic codes
  3. Versions and VM generations

How the examples are checked

Every Captain example in this book is checked against the real toolchain:

  • a block marked captain is a whole module, and captain check must pass;
  • a block marked captain fail is a whole module that must be refused, and when the block names diagnostic codes, the checker must report each one;
  • a block marked captain fragment is a piece of a program, shown to make a point about syntax. It is not checked on its own, and the text around it says what it belongs to;
  • a console session marked run is executed, command by command, and its output compared with the book's. A line ... stands for lines left out, and [..] for text left out of a line, such as a digest.