Learn Tin · Part 1: The language · Chapter 1
Hello, Tin
Write a program, run it, and read an error message.
Your first program
A Tin program is a file that ends in .tin. It starts running at a function called
main. Here is the smallest useful one:
tin run hello.tinfn main() {
print("Hello, Tin!")
} Hello, Tin! fn declares a function. The body goes between { and }.
print writes a line of text. The box under the code is what the program printed.
Running it
You have two options:
- In the browser. Open the playground, paste the code and press Run. Nothing to install. The compiler runs in your browser.
- On your computer. With Node 24 or newer, clone the repository and run the file:
git clone git@github.com:cagataycali/tin && cd tin
npm install
./bin/tin run hello.tin tin run compiles the file to WebAssembly and runs it. You never see the compile step:
on a small file it takes a few milliseconds.
Text with values in it
Put any expression inside { } in a string, and its value is written there. This is called
interpolation. let gives a value a name.
tin run greet.tin// A line starting with // is a comment. Tin ignores it.
fn main() {
let name = "Ada"
print("Hello, {name}!") // {name} is replaced by its value
print("{name} has {name.len} letters")
print("2 + 3 = {2 + 3}") // any expression works inside { }
} Hello, Ada!
Ada has 3 letters
2 + 3 = 5 When a function is a single expression, you can write it on one line with =>:
tin run short.tinfn main() => print("A one-line program.") A one-line program. Reading an error
You will make mistakes, so it is worth learning to read the compiler's answer early. Here the name is misspelled:
tin check typo.tinfn main() {
let greeting = "Hello"
print(greting)
} error: unknown name 'greting'
--> typo.tin:3:9
|
3 | print(greting)
| ^^^^^^^
= note: did you mean 'greeting'?
= fix: use greeting Every error has the same shape: what went wrong, the file, line and column (typo.tin:3:9), the
line itself with the problem underlined, and often a note that says what to change. For some
errors the compiler knows the exact edit (the fix line), and tin fix typo.tin applies
it for you: here it would write greeting.
Two mistakes people often make when they come from other languages:
tin check toplevel.tinprint("Hello, Tin!") error: expected a declaration (fn, tool fn, type, agent, let, test), found 'print'
--> toplevel.tin:1:1
|
1 | print("Hello, Tin!")
| ^^^^^ Code runs only inside functions. The top of a file is for declarations.
tin check mix.tinfn main() {
let year = 2026
print("It is " + year)
} error: '+' joins two strings, found string and int
--> mix.tin:3:9
|
3 | print("It is " + year)
| ^^^^^^^^^^^^^^^
= note: put the value in the string instead: "total: {n}"
= fix: interpolate it Tin never turns a number into text by itself. Write "It is {year}" instead.
Tin checks the whole program before it runs any of it. If tin run prints an error,
nothing ran, not even the lines above the mistake.
Trying one line at a time
tin repl lets you type an expression and see its value right away, which is handy for
checking how something behaves. Type 1 + 2 * 3 and it answers 7. Leave with Ctrl-D.
Tasks
●○○ Task 1: Introduce yourself
Write a program that stores your name and your city with let, then prints two lines:
My name is … and I live in ….
Solution
tin run task-1.solution.tinfn main() {
let name = "Grace"
let city = "Arlington"
print("My name is {name}.")
print("I live in {city}.")
} My name is Grace.
I live in Arlington. ●○○ Task 2: Fix it from the error
This program doesn't compile. Read the error, then fix the program so it prints Hello from Tin!.
tin check task-2.tinfn main() {
let first = "Tin"
print("Hello from {frist}!")
} error: unknown name 'frist'
--> task-2.tin:3:22
|
3 | print("Hello from {frist}!")
| ^^^^^
= note: did you mean 'first'?
= fix: use first Solution
tin run task-2.solution.tinfn main() {
let first = "Tin"
print("Hello from {first}!")
} Hello from Tin! ●●○ Task 3: Let Tin do the arithmetic
Print Minutes in a week: … with the number filled in. Don't work it out yourself: put the
calculation inside the string.
Solution
tin run task-3.solution.tinfn main() {
print("Minutes in a week: {7 * 24 * 60}")
} Minutes in a week: 10080 What's next
Next: Values and types. let, var, numbers, strings and how Tin infers types.
In the reference: Programs · Strings · The tin command