Your first program
Write a function as a table, run it with ridgunc run, and build a native executable.
Create a file named hello.rg:
fn :: greet String => String
greet "" = "Hello, mysterious traveler!"
greet "Root" = "Hey there, Root! Careful what you delete today."
greet name = "Hello, {name}! Welcome to Ridgun."
fn :: main => ()
main =
echo (greet "Ada")
echo (greet "Root")
echo (greet "")
Read it as a table. The first line is the signature: greet takes a String and gives a String. Each line below it is a clause, and the first clause whose pattern matches the argument answers. {name} inside a string puts the value of name there.
Run it
ridgunc run hello.rg
Hello, Ada! Welcome to Ridgun.
Hey there, Root! Careful what you delete today.
Hello, mysterious traveler!
ridgunc run compiles the file and runs it straight away. ridgunc check hello.rg only checks the types, which is the fastest way to find a mistake.
Build an executable
ridgunc build hello.rg -o hello
./hello
hello is a static ELF64 executable. Copy it to any Linux machine with the same processor and it runs: there is no runtime to install.
Guards
When the choice depends on a condition rather than a pattern, use guards. Each | line is tried in order:
fn :: size Int => String
size n =
| n == 0 = "nothing"
| n < 100 = "small"
| otherwise = "large"
Next, start a project with stable.