Examples
Every file in examples/. npm test runs each one and checks its output against the one shown on its page.
The language
- 01-hello The smallest Tin program.
- 02-fizzbuzz Functions, ranges, and
ifas an expression. - 03-shapes Sum types and exhaustive
match. - 04-pipelines Pipelines and methods.
- 05-errors No null, no exceptions.
- 06-generics Generics are monomorphised: Stack<int> and Stack<string> each compile to their own specialised WebAssembly, with no boxing and no runtime type checks.
- 07-tree A recursive sum type: an immutable binary search tree.
- 08-closures Functions are values.
- 09-concurrency The event loop, without coloured functions.
- 10-mandelbrot Floating-point number crunching, drawn in ASCII.
- 11-sieve Arrays and tight loops: the sieve of Eratosthenes.
- 12-words Strings and maps: count the words in a text.
- 13-bank Structs with methods, and errors as ordinary values.
- 14-life Conway's Game of Life on a small torus.
- 15-values Arrays and structs are values, like numbers.
- 16-tests Tests live next to the code they test.
- 17-numbers Numbers never wrap around silently.
- 18-rates Frequency is a unit, like Duration.
- 19-equality == compares values, not identities: two arrays, structs or enums are equal when their parts are.
- 20-timestamps i64 is a 64-bit integer, for values that outgrow int's 32 bits: nanosecond timestamps, byte counts, big counters.
- 21-loops Three loops:
for x in xs,for i, x in xs(with the index), andloop { }, which runs until abreakorreturn. - 22-tuples Tuples group a few values without declaring a type: (lo, hi), ("x", 1.5).
- 23-bits Bits, for registers and flags: & | ^ on int and i64, and x.shl(n) / x.shr(n).
- 24-patterns Nested patterns.
- 25-tasks Structured concurrency: tasks have owners, and waiting has limits.
- 26-traits Traits: say what a generic function needs, and get the error at the call.
- 27-order The standard library's traits: Ord, Show and Eq.
- 28-chars char: one Unicode character.
- 29-iterators for over your own types.
- anthropic/batch The Anthropic API beyond one agent turn, from Tin: count tokens, list models, send a Message Batch, wait for it and read the results.
- anthropic/editor The text editor tool (text_editor_20250728): Claude views and edits files under ./workspace.
- anthropic/files The Files API: upload once, then refer to the file by id.
- anthropic/memory Claude's memory tool (memory_20250818): the model asks for file operations under /memories and this program runs them, in one JSON file next to it.
- anthropic/research An agent with tools Anthropic runs: web search, web fetch and code execution, plus an MCP server.
- cli/hello args() and exit(code): a command-line program.
- interop/main Calling JavaScript from Tin.
- learn/00-readme/hero
- learn/01-hello/greet A line starting with // is a comment.
- learn/01-hello/hello
- learn/01-hello/mix.fails
- learn/01-hello/short
- learn/01-hello/task-1.solution
- learn/01-hello/task-2.fails
- learn/01-hello/task-2.solution
- learn/01-hello/task-3.solution
- learn/01-hello/toplevel.fails
- learn/01-hello/typo.fails
- learn/02-values/bools
- learn/02-values/char-vs-string.fails
- learn/02-values/chars
- learn/02-values/format
- learn/02-values/i64
- learn/02-values/let-reassign.fails
- learn/02-values/let-var
- learn/02-values/no-mixing.fails
- learn/02-values/numbers
- learn/02-values/overflow.panics
- learn/02-values/strings
- learn/02-values/task-1.solution
- learn/02-values/task-2.fails
- learn/02-values/task-2.solution
- learn/02-values/task-3.solution
- learn/02-values/types
- learn/02-values/wrong-type.fails
- learn/03-functions/arity.fails
- learn/03-functions/arrow
- learn/03-functions/define fn name(parameter: type, ...): result type { body }
- learn/03-functions/missing-value.fails
- learn/03-functions/no-result No result type: the function does something instead of computing a value.
- learn/03-functions/param-types.fails
- learn/03-functions/recursion A function can call itself.
- learn/03-functions/return
- learn/03-functions/task-1.solution
- learn/03-functions/task-2.solution Divisible by 4, except centuries, except every 400 years.
- learn/03-functions/task-3.fails
- learn/03-functions/task-3.solution
- learn/04-control/block-value
- learn/04-control/break-continue
- learn/04-control/for-items
- learn/04-control/for-range
- learn/04-control/if
- learn/04-control/if-value
- learn/04-control/loop
- learn/04-control/no-truthy.fails
- learn/04-control/task-1.solution
- learn/04-control/task-2.solution
- learn/04-control/task-3.solution
- learn/04-control/while
- learn/05-structs/change
- learn/05-structs/equality
- learn/05-structs/methods
- learn/05-structs/missing-field.fails
- learn/05-structs/nested
- learn/05-structs/shorthand
- learn/05-structs/struct A struct type: a name for a group of named fields.
- learn/05-structs/task-1.solution
- learn/05-structs/task-2.solution
- learn/05-structs/task-3.solution
- learn/05-structs/tuples A tuple groups a few values without declaring a type.
- learn/06-enums/forgot.fails
- learn/06-enums/guards
- learn/06-enums/payload Each variant can carry its own data.
- learn/06-enums/positional Variants can also carry values by position, like a function call.
- learn/06-enums/simple A sum type: a value that is exactly one of these.
- learn/06-enums/task-1.solution
- learn/06-enums/task-2.solution A sum type can contain itself: an expression is a number, or two expressions combined.
- learn/06-enums/task-3.solution
- learn/06-enums/values match works on ints and strings too.
- learn/07-errors/no-null.fails
- learn/07-errors/option Option<T> is Some(value) or None.
- learn/07-errors/or
- learn/07-errors/own-error The error can be your own sum type, so callers can tell the failures apart.
- learn/07-errors/panic.panics panic is for bugs: things that should never happen.
- learn/07-errors/question
- learn/07-errors/question-option ? works on Option too, in a function that returns an Option.
- learn/07-errors/result Result<T, E> is Ok(value) or Err(error): an operation that can fail, and why.
- learn/07-errors/task-1.solution
- learn/07-errors/task-2.solution
- learn/07-errors/task-3.solution
- learn/08-collections/arrays
- learn/08-collections/change
- learn/08-collections/empty
- learn/08-collections/empty.fails
- learn/08-collections/maps
- learn/08-collections/one-type.fails
- learn/08-collections/out-of-bounds.panics
- learn/08-collections/sets
- learn/08-collections/sort
- learn/08-collections/task-1.solution
- learn/08-collections/task-2.solution
- learn/08-collections/task-3.solution
- learn/09-closures/capture-var.fails
- learn/09-closures/closure
- learn/09-closures/fn-values
- learn/09-closures/map-filter
- learn/09-closures/pipe
- learn/09-closures/reduce
- learn/09-closures/sort-by
- learn/09-closures/task-1.solution
- learn/09-closures/task-2.solution
- learn/09-closures/task-3.solution Returns a function.
- learn/10-generics/generic-sum A generic sum type: a tree of anything.
- learn/10-generics/generic-type Types can take parameters too.
- learn/10-generics/infer.fails
- learn/10-generics/largest
- learn/10-generics/not-comparable.fails
- learn/10-generics/ord
- learn/10-generics/task-1.solution
- learn/10-generics/task-2.solution
- learn/10-generics/task-3.solution
- learn/10-generics/traits
- learn/10-generics/traits-missing.fails
- learn/10-generics/why Without generics you'd write the same function once per type.
- learn/11-values/copy
- learn/11-values/copy-struct
- learn/11-values/inout
- learn/11-values/inout-let.fails
- learn/11-values/inout-method
- learn/11-values/iterator
- learn/11-values/param A parameter is a copy too.
- learn/11-values/param-let.fails
- learn/11-values/task-1.solution
- learn/11-values/task-2.solution
- learn/11-values/task-3.solution
- learn/12-units/convert
- learn/12-units/durations
- learn/12-units/freq-mix.fails
- learn/12-units/frequency
- learn/12-units/mix.fails
- learn/12-units/sleep
- learn/12-units/task-1.solution
- learn/12-units/task-2.solution
- learn/12-units/task-3.solution Waits 100ms, then 200ms, then 400ms ...
- learn/13-modules/arm
- learn/13-modules/lib/dates
- learn/13-modules/lib/dates2
- learn/13-modules/lib/joints lib/joints.tin: a file of types and functions for other files to use.
- learn/13-modules/lib/money
- learn/13-modules/lib/report lib/report.tin: it uses Joint, so it imports joints.tin itself.
- learn/13-modules/lib/temps
- learn/13-modules/task-1.solution
- learn/13-modules/task-2.fails
- learn/13-modules/task-2.solution dates2.tin is dates.tin with its function renamed to dayLabel.
- learn/13-modules/twice.fails
- learn/14-tests/assert.test
- learn/14-tests/beside-main
- learn/14-tests/beside-main.test
- learn/14-tests/failing.test
- learn/14-tests/first.test
- learn/14-tests/rotted.fails
- learn/14-tests/task-1.solution.test
- learn/14-tests/task-2.solution.test
- learn/15-first-agent/hello
- learn/15-first-agent/local
- learn/15-first-agent/memory
- learn/15-first-agent/task-1.solution
- learn/15-first-agent/task-2.solution
- learn/15-first-agent/trace run: --trace
- learn/15-first-agent/typed
- learn/16-tools/events
- learn/16-tools/failing-tool
- learn/16-tools/first-tool
- learn/16-tools/generic.fails
- learn/16-tools/not-data.fails
- learn/16-tools/schema.tools
- learn/16-tools/task-1.solution
- learn/16-tools/task-2.solution.tools
- learn/17-typed-replies/float.fails
- learn/17-typed-replies/order
- learn/17-typed-replies/small
- learn/17-typed-replies/task-1.solution
- learn/17-typed-replies/task-2.solution
- learn/17-typed-replies/try
- learn/17-typed-replies/wrapped
- learn/18-approval/approve
- learn/18-approval/approve-yes run: --yes
- learn/18-approval/approved run: --yes
- learn/18-approval/denied
- learn/18-approval/direct.fails
- learn/18-approval/sneaky.fails
- learn/18-approval/task-1.solution run: --yes
- learn/18-approval/task-2.solution
- learn/19-capabilities/fetch.caps
- learn/19-capabilities/reach.caps run: --reach charge
- learn/19-capabilities/shop.caps
- learn/19-capabilities/task-1.solution.caps
- learn/19-capabilities/task-2.solution.caps
- learn/20-teams/critic
- learn/20-teams/pipeline
- learn/20-teams/sub-agent
- learn/20-teams/task-1.solution
- learn/20-teams/task-2.solution
- learn/21-concurrency/agents
- learn/21-concurrency/budget
- learn/21-concurrency/precedence.fails
- learn/21-concurrency/spawn
- learn/21-concurrency/stop
- learn/21-concurrency/task-1.solution
- learn/21-concurrency/task-2.solution
- learn/21-concurrency/within
- learn/22-code-as-action/escape
- learn/22-code-as-action/forever
- learn/22-code-as-action/task-1.solution
- learn/22-code-as-action/task-2.solution
- learn/22-code-as-action/typo
- learn/22-code-as-action/weather run: --replay tests/tapes/agents-09-code.json
- learn/23-replay/calc run: --replay tests/tapes/agents-05-claude.json
- learn/23-replay/changed.panics run: --replay tests/tapes/agents-05-claude.json
- learn/23-replay/dice run: --replay examples/learn/23-replay/dice.tape.json
- learn/23-replay/regression.test run: --replay tests/tapes/agents-05-claude.json
- learn/23-replay/task-1.solution run: --replay examples/learn/23-replay/coins.tape.json
- learn/23-replay/task-2.solution.test run: --replay tests/tapes/agents-05-claude.json
- learn/24-models/budget
- learn/24-models/claude run: --replay tests/tapes/agents-05-claude.json
- learn/24-models/swap
- learn/24-models/task-1.solution
- learn/24-models/task-2
- learn/24-models/task-2.solution
- learn/25-js-interop/data
- learn/25-js-interop/hello-js
- learn/25-js-interop/missing.panics
- learn/25-js-interop/node
- learn/25-js-interop/task-1.solution
- learn/25-js-interop/task-2.solution run: --yes
- learn/25-js-interop/throws
- learn/25-js-interop/tool.fails
- learn/25-js-interop/wrong-type.panics
- learn/26-fleet/fleet run: --replay tests/tapes/agents-08-fleet.json --yes
- learn/26-fleet/fleet.caps
- learn/26-fleet/task-1.solution.test
- learn/26-fleet/task-2.solution.caps run: --reach scrap
- learn/27-cli/greet
- learn/27-cli/messy
- learn/27-cli/new-project hello: a Tin program with one agent.
- learn/27-cli/tally Reads numbers, one per line, until a blank line.
- learn/27-cli/task-1.solution
- learn/27-cli/task-2.solution A to-do list driven by commands: add <text>, done <number>, list, quit.
- learn/28-browser/shop
- learn/29-voice/called.fails
- learn/29-voice/handlers
- learn/29-voice/listen.caps
- learn/29-voice/model.fails
- learn/29-voice/session
- learn/29-voice/task-1
- learn/29-voice/task-1.solution
- learn/30-server/agent.serve
- learn/30-server/grants.fails
- learn/30-server/hello.serve
- learn/30-server/injection.fails
- learn/30-server/parsed.fails
- learn/30-server/redirect.fails
- learn/30-server/task-1.solution.serve
- learn/30-server/types.serve
- learn/31-telemetry/spans
- learn/31-telemetry/task-1.solution
- learn/32-robots/arm
- learn/32-robots/bare.fails
- learn/32-robots/task-1.solution
- learn/32-robots/typo.fails
- learn/33-policies/forms
- learn/33-policies/tape
- learn/33-policies/task-1.solution
- learn/33-policies/wave
- learn/34-robot-safety/drive
- learn/34-robot-safety/gate
- learn/34-robot-safety/reply.fails
- learn/34-robot-safety/task-1.solution
- mcp/client A Tin program using an MCP server's tools as typed functions.
- mcp/units A Tin program as an MCP server: its tool fns become MCP tools, with schemas from the types.
- modules/kinematics A second file: everything declared here is visible to the files that import it.
- modules/main A program in two files.
- mujoco/wave The same wave as examples/robots/wave.tin, in real physics: one word picks the world.
- namespaces/arm Imported with
import "./arm.tin" as arm: everything here is arm.name to the importer. - namespaces/base Imported with
import "./base.tin" as base. - namespaces/main Namespaced modules:
import "./file.tin" as nameputs the file's types, functions, constants and agents undername., so two files may use the same names. - packages/app/main A program that uses the geometry package from ../geometry (see tin.toml).
- packages/geometry/lib geometry: small 2D helpers for robot arms.
- packages/geometry/vec Vectors in the plane.
- policies/walk A humanoid walking on a learned policy: the holosoma ONNX checkpoint on the Unitree G1, in MuJoCo.
- py/stats Calling Python from Tin:
import py "module"names a module (a .py file next to this one, or anything installed), and eachextern fnin the block is a function in it. - robots/pick Waypoints, then a chunked policy, then seeded noise on top: every run of this program is identical.
- robots/wave Wave an SO-101 arm's shoulder for five seconds in the built-in kinematic world.
- server/shop A small shop backend: typed routes, an agent behind a route, a voice line, and request input that the compiler keeps away from outside code.
- wasi/stats A command-line tool with no JavaScript in it: build it for WASI, run it with wasmtime.
Agents
- 01-tools Tools and agents are part of the language.
- 02-typed A typed call: the type you expect decides the shape of the reply.
- 03-team Agents compose with everything else in the language.
- 04-approval
guarded tool fnputs a human in the loop. - 05-claude The same language features, with a real model. Replays a recorded tape.
- 06-chat An interactive chat with a tool, in thirty lines. Replays a recorded tape.
- 07-capabilities Capabilities are checked by the compiler, before anything runs.
- 08-fleet A fleet: one planner, two workers, and a person who approves the risky part. Replays a recorded tape.
- 09-code Code as action: the model answers by writing a program. Replays a recorded tape.
- 10-try Handling a failed agent call.
- 11-timestamps 64-bit integers at the agent boundary.
- 12-resume Saving and restoring an agent.
- 13-voice Talking agents: a
voice agentholds a live, two-way conversation with a speech-to-speech model. - 14-call A phone call with an agent: microphone in, speaker out, until the call ends.
- hello-native A hello agent for
tin build --native(npm run smoke:native runs it live on Amazon Bedrock). Replays a recorded tape.