Skip to content

Compile-time correctness for the BEAM.

Gale is a statically typed language that compiles to readable Elixir. Model your data with types, check contracts with an optional prover, and build on Elixir’s libraries and OTP.
Terminal window
curl -fsSL https://gale-lang.org/install.sh | bash

Describe the states your data can take. Gale checks each branch and reports missing cases when a match does not cover them all:

pub type Delivery =
| Pending
| Shipped(tracking: String)
| Delivered
pub fn status(delivery: Delivery) -> String {
case delivery {
Pending -> "Preparing your order"
Shipped(tracking: tracking) -> "Track your order: #{tracking}"
Delivered -> "Delivered"
}
}

A function that receives declares its mailbox. Gale checks typed sends and receives against that declaration, including the reply destination:

alias gale_std.process
pub type Command =
| Add(amount: Integer)
| Fetch(reply_to: process.Pid<Integer>)
fn counter(total: Integer) receives Command -> Integer {
receive {
Add(amount: amount) -> counter(total + amount)
Fetch(reply_to: reply_to) -> {
process.send(reply_to, total)
counter(total)
}
}
}

These types do not prevent foreign Elixir code from sending other values, or guarantee message delivery or process survival. See processes for examples and the boundary with native code.

Bind an Elixir function with an explicit foreign declaration. The declared signature is trusted; explicitly listed exceptions become typed Result errors:

pub extern exception "ArgumentError" ArgumentError {
message: String
}
extern raises "String.to_integer" to_integer(value: String) -> Result<Integer, ArgumentError>
pub extern "String.trim" trim(value: String) -> String
pub fn parse_count(value: String) -> Result<Integer, ArgumentError> {
to_integer(trim(value))
}

Generated sidecars are ordinary Elixir with @specs, callable from the rest of your codebase as-is. Enable optional runtime checks in tests to catch type and contract violations at Elixir boundaries.

Types tell you that clamp returns an integer. Its contract goes further: the result must fall between lower and upper. Run gale verify to check that the implementation keeps this promise whenever lower <= upper:

pub fn clamp(value: Integer, lower: Integer, upper: Integer) -> Integer
requires { lower <= upper }
ensures { result >= lower and result <= upper }
{
cond {
value < lower -> lower
value > upper -> upper
true -> value
}
}

Compilation checks types and contract formulas. Verification is a separate step: a function with a false contract can compile, but the verifier will not establish that contract.