Skip to main content

Your first program

This program defines a recursive function and evaluates factorial 6:

factorial :: Int -> Int.
factorial =
\|(0) -> 1
|(n) -> n * factorial (n - 1).
factorial 6.

Check the program without running it. Success produces no output:

cabal run jazz -- examples/functions/factorial.jz

Then run it:

cabal run jazz -- --run examples/functions/factorial.jz

Result:

720

Int -> Int guarantees that factorial accepts and returns an integer. The pattern clauses are tried from top to bottom: zero stops the recursion, while the second clause handles every other integer. The final expression supplies the program's result.

Continue with bindings and functions and control flow. Exact source forms are listed in the expression grammar.