Learn Capa

A step-by-step tutorial. Twelve chapters, hands-on. Every chapter has a runnable program and a focused new idea. Read it in order on the first pass; come back as a reference later.

Before you start

You need:

No prior capability-language experience is assumed. If you have written Python, Go, Rust, or any C-family language, you will feel at home. Where Capa is unusual is called out explicitly.

The twelve chapters

Each chapter is short (5-10 minutes of reading plus typing). You can stop after any chapter and have a working program. The capability discipline starts to bite in chapter 8; the first seven chapters are a normal-looking language so the surface stays familiar before the unusual ideas arrive. The final chapter is a worked example that exercises everything.

  1. Hello, Capa Your first program. The shape of main.
  2. Values and types Primitives, let vs var, type inference, string interpolation.
  3. Functions Signatures, parameters, return types, named arguments.
  4. Control flow if, while, for, ranges, statement vs expression.
  5. Collections List, Map, Set, higher-order methods.
  6. Structs and sum types Defining your own types, pattern matching on variants.
  7. Errors as values Option<T>, Result<T, E>, the ? operator.
  8. Your first capability What Stdio really is. Why main declares it. The discipline.
  9. Attenuating capabilities restrict_to. Monotonic narrowing. Least-authority programs.
  10. Defining your own capability capability X, impl X for Y. Library contracts.
  11. Modules and visibility import, pub, CAPA_PATH.
  12. A small project Putting it together. A real CLI tool in Capa.

Once you finish (or want to look something up), the language reference and the standard library are the dense companions to this track.