Skip to content

Hello World

Every Nic program starts with a main function. Here's the simplest program:

nic
fn main() -> unit {
    println("Hello, World!");
    return;
}

Running the Example

Save this as hello.nic and run:

bash
$ cabal run nicc -- --compile hello.nic
$ ./hello
Hello, World!

Explanation

  • fn main() — Declares the entry point function named main
  • -> unit — The function returns unit (equivalent to void in C)
  • println(...) — Built-in function from the prelude that prints a line
  • return; — Explicit return is required (returns unit implicitly)
  • Semicolons terminate all statements

The Prelude

Nic automatically imports a prelude containing common types and functions:

  • Option[T] — Optional values (Some(x) or None)
  • Result[T, E] — Error handling (Ok(x) or Err(e))
  • print, println — Basic output functions

You don't need to import these—they're available everywhere.

A Slightly Longer Example

nic
fn main() -> unit {
    println("Welcome to Nic!");
    println("A systems programming language");
    println("with pattern matching and explicit memory control.");
    return;
}

Next

Now that you can run a program, let's learn about Variables.

Released under the MIT License.