SagaSaga
Guide

Getting Started

Saga is a statically typed functional language that compiles to the BEAM (Erlang's virtual machine). It has type inference, algebraic data types, pattern matching, and an effect system for managing side effects. Here's a quick taste:

fun greet : String -> String
greet name = $"Hello, {name}!"

main () = {
  dbg (greet "world")
}

If you haven't installed Saga yet, head to Installation first.

Hello, World

Create a file called hello.saga:

main () = {
  dbg "Hello, world!"
}

Every Saga program needs a main function as its entry point. main takes Unit (written ()) as its only parameter. dbg prints any value to stdout.

Run it:

saga run hello.saga

Printing with effects

dbg is handy for quick output, but Saga's standard approach to I/O uses the effect system. Here is the same program using print!:

main () = {
  print! "Hello, world!"
} with console

print! is an effect operation (the ! marks it), and with console provides the handler that writes to stdout. Don't worry about what that means yet. The full story is in Effects & Handlers. For now, dbg is fine for printing while you learn the basics.

Commands

saga run file.saga     # compile and run
saga build file.saga   # compile only
saga check file.saga   # type-check without compiling
saga emit file.saga    # print generated Core Erlang to stdout
saga test              # run the test suite in tests/