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 namedmain-> unit— The function returnsunit(equivalent tovoidin C)println(...)— Built-in function from the prelude that prints a linereturn;— Explicit return is required (returnsunitimplicitly)- Semicolons terminate all statements
The Prelude
Nic automatically imports a prelude containing common types and functions:
Option[T]— Optional values (Some(x)orNone)Result[T, E]— Error handling (Ok(x)orErr(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.