Hello World
Your first program
Section titled “Your first program”Create a file called hello.almd:
main.almd
effect fn main() -> Result[Unit, String] = {
println("Hello, world!")
ok(())
} Press Run to compile and execute this in your browser
No installation needed to try it: Run in your browser compiles this with the real Almide compiler — the same one you install locally, shipped to this page as WebAssembly — and runs the result. Edit the code and press Run again.
To run it on your machine instead:
almide run hello.almdOutput:
Hello, world!Breaking it down
Section titled “Breaking it down”effect fn— this function has side effects (printing to stdout)main()— the entry point of the program-> Result[Unit, String]— returnsUniton success, or aStringerrorprintln(...)— print a line to stdoutok(())— return success with the Unit value()
Adding logic
Section titled “Adding logic” main.almd
fn greet(name: String) -> String =
"Hello, ${name}!"
effect fn main() -> Result[Unit, String] = {
let names = ["Alice", "Bob", "Charlie"]
for name in names {
println(greet(name))
}
ok(())
} Press Run to compile and execute this in your browser
Writing tests
Section titled “Writing tests”Add a test block anywhere in your .almd file:
fn add(a: Int, b: Int) -> Int = a + b
test "addition" { assert_eq(add(1, 2), 3) assert_eq(add(0, 0), 0) assert_eq(add(-1, 1), 0)}Run tests:
almide test hello.almdBuilding a binary
Section titled “Building a binary”almide build hello.almd -o hello./helloNext steps
Section titled “Next steps”- Types & Values — learn about Almide’s type system
- Functions — pure functions and effect functions