Compile-time correctness for the BEAM.
curl -fsSL https://gale-lang.org/install.sh | bashStatic types and pattern matching
Section titled “Static types and pattern matching”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" }}Typed messages
Section titled “Typed messages”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.
Seamless Elixir interop
Section titled “Seamless Elixir interop”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.
Prove your contracts
Section titled “Prove your contracts”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) -> Integerrequires { 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.