Menu
Try in Playground

Zero Hello World: Write and Run Your First .0 Program

Your first Zero program — what every piece of the canonical hello-world means, how to run it with zero run, and why even a five-line program already uses World, raises, and check.

This page includes runnable editors — edit, run, and see output instantly.

Write the File

Open your editor and save the following five lines as hello.0 somewhere convenient — or just click Run on the block below:

That's it — a complete Zero program. To run it locally:

zero run hello.0

You should see:

hello from zero

If you got command not found, jump back to Install Zero and make sure zero --version works first.

Unpacking Every Token

Even this tiny program already shows off most of what makes Zero different. Let's read it left to right.

pub

pub marks a declaration as public — visible outside its current module. The runtime needs to find main from outside the file's own scope, so main has to be pub. A private helper function inside the same file wouldn't need it.

fun

fun introduces a function declaration. Zero uses fun, not fn (Rust) or func (Go) or function (JavaScript). One keyword, used the same way every time.

main

The conventional entry point name. When a Zero executable target runs, the runtime looks for pub fun main(world: World) and calls it. You can name other functions whatever you want, but main is reserved by convention for the program entry.

(world: World)

The single parameter is named world and has type World. The runtime constructs a World value before calling main and passes it in. That value carries the program's capabilities: access to stdout, stdin, the filesystem, the network, and so on, depending on what the runtime decides to grant.

The parameter name is yours to pick — (w: World) or (io: World) would compile fine. The convention in examples is world, and we'll stick with that.

-> Void

The return type. Void means the function returns nothing useful — it's there for its side effects, not its value. Many functions you write will return real types like i32 or a shape you defined.

raises

Bare raises (with no specific error type) on main says "this function can fail". For main, that means the program can exit with a nonzero status if any check inside the body propagates an error up. We'll see narrower forms — raises { InvalidInput }, for example — in Raises and Check.

check world.out.write("hello from zero\n")

This is the line that actually does something. Three sub-pieces:

  • world.out — the standard-output stream, exposed as a field on the World capability.
  • .write("hello from zero\n") — a method that writes a string to that stream. It returns a result that could indicate failure (the write could fail; the stream could be closed).
  • check — propagates that failure up if it happens. Without check, the compiler would complain that the result of write is being discarded silently.

The \n at the end is a literal newline. Without it, the output would not flush to a new line and your shell prompt would land on the same line as your message.

What Just Happened

When you ran zero run hello.0:

  1. The compiler parsed your file and type-checked it.
  2. It produced a small native executable for your platform.
  3. The runtime constructed a World capability for the current process.
  4. It called main(world).
  5. Your code wrote "hello from zero\n" to that world's out stream — which is connected to your terminal's stdout.
  6. main returned Void, the runtime cleaned up, and the program exited with status 0.

There is no garbage collector, no hidden runtime initialization, no implicit module bootstrap. The whole program is the function you wrote, plus the standard-library code it called.

Try a Small Change

Make the program take a binding for the message before writing it:

Run it again — same output, but now you've seen let bindings and confirmed that strings are first-class values you can pass around.

A Failing Variant

What happens if you forget the check?

pub fun main(world: World) -> Void raises {
    world.out.write("oops\n")
}

zero check hello.0 will refuse to compile this. The result of write is a fallible value; ignoring it is a compile error. You either check it (propagate the error) or handle it explicitly. This is the same idea as Rust's must_use results, only enforced for every fallible call.

Next: The Zero CLI

You used zero run here. The CLI has a small set of commands worth knowing — check, run, build, test, fix, explain — each with a structured --json mode designed for agents to consume.

Frequently Asked Questions

What is the hello world program in Zero?

The canonical Zero hello world is five lines: pub fun main(world: World) -> Void raises { check world.out.write("hello from zero\n") }. Save it as hello.0 and run zero run hello.0.

What does pub fun main mean in Zero?

pub makes a declaration public — visible outside its module. fun declares a function. main is the conventional entry point Zero looks for in an executable target. Together, pub fun main declares the public entry point the runtime calls when the program starts.

Why does main take a World parameter?

Zero has no global I/O. Anything that talks to the outside world — stdout, stdin, files, the network — goes through capabilities passed in explicitly. The runtime hands main a World value, and that value (or pieces of it) is the only way functions can do I/O. It makes side effects visible in function signatures.

What do raises and check do in the hello world?

raises on main declares that the function can fail. check world.out.write(...) calls a fallible function and, if it fails, propagates the error up to the caller — here, that's the runtime, which exits with a nonzero status. Without check, the compiler would refuse to compile the call because the error would be unhandled.

What file extension does Zero use?

Zero source files use the .0 extension (the digit zero, not the letter O). A hello.0 file is a Zero source file. The compiler is invoked with commands like zero check hello.0 and zero run hello.0.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED