Hello World
Your first program
Section titled “Your first program”Create a file called hello.almd:
effect fn main() -> Result[Unit, String] = { println("Hello, world!") ok(())}Run it:
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”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(())}Hello, Alice!Hello, Bob!Hello, Charlie!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