GALA

Sum types, pattern matching, default parameters, and zero-reflection JSON that Go is missing — compiled to native Go binaries

Try in Playground View on GitHub

Sum Types and Pattern Matching for Go — Without Leaving the Ecosystem

GALA (Go Alternative LAnguage) is a modern programming language that transpiles to Go. The 2024 Go Developer Survey confirmed that sum types and enums are the #1 most-requested missing feature in Go. As of Go 1.25, they still don’t exist. GALA delivers them today — along with exhaustive pattern matching, Option[T]/Either[A,B]/Try[T] monads, default parameters with named arguments, a zero-reflection JSON codec, regex pattern matching extractors, and immutable collections — all compiling to a single native binary through the standard Go toolchain.

Unlike libraries like samber/lo or IBM/fp-go that bolt functional patterns onto Go’s syntax, GALA adds these features at the language level with clean, concise syntax. Every Go library works out of the box. Your existing Go modules, third-party packages, and tooling remain fully compatible. GALA extends Go with the type-safety features it deliberately omits, while preserving Go’s performance, deployment simplicity, and ecosystem.

GALA’s transpiler performs type inference, exhaustive match checking, and immutability enforcement at compile time. The generated Go code is clean and readable — you can always inspect what GALA produces. There is no runtime overhead beyond what the equivalent hand-written Go would have.

Features

Sealed Types

Define closed type hierarchies. The compiler rejects incomplete matches — no forgotten cases at runtime.

sealed type Shape {
    case Circle(Radius float64)
    case Rectangle(Width float64, Height float64)
}

Learn about sealed types

Pattern Matching

Exhaustive pattern matching with destructuring, guards, and expression results — far beyond Go's switch.

val msg = shape match {
    case Circle(r)       => f"r=$r%.1f"
    case Rectangle(w, h) => f"${w * h}%.2f"
}

Learn about pattern matching

Immutability by Default

val bindings are immutable. Struct fields are immutable. Auto-generated Copy() for safe updates.

struct Config(Host string, Port int)
val updated = config.Copy(Port = 8080)

Learn about immutability

Monadic Error Handling

Option[T], Either[A,B], and Try[T] replace nil checks and if err != nil with composable pipelines.

val result = divide(10, 2)
    .Map((x) => x * 2)
    .FlatMap((x) => divide(x, 3))
    .Recover((e) => 0)

Learn about error handling

Functional Collections

Immutable List, Array, HashMap, HashSet, TreeSet, TreeMap with Map, Filter, FoldLeft, Collect, and more.

val nums = ArrayOf(1, 2, 3, 4, 5)
val evens = nums.Filter((x) => x % 2 == 0)
val sum = nums.FoldLeft(0, (acc, x) => acc + x)

Learn about collections

Default Parameters & Named Arguments

No more functional options pattern or config structs. Default parameter values and named arguments work directly in function signatures.

func connect(host string,
    port int = 8080, tls bool = true,
) Connection

connect("localhost", tls = false)

Learn about default parameters

Zero-Reflection JSON Codec

Compile-time StructMeta[T] generates typed serialization with no reflection, no struct tags. Builder pattern for Rename, Omit, and naming strategies.

val codec = Codec[Person](SnakeCase())
val jsonStr = codec.Encode(person).Get()
val decoded = codec.Decode(jsonStr)

Learn about JSON codec

Regex Pattern Matching

Compile-safe regex with extractors that destructure capture groups directly in match expressions. No manual group indexing.

val date = regex.MustCompile(
    "(\\d{4})-(\\d{2})-(\\d{2})")

input match {
    case date(Array(y, m, d)) =>
        s"$y/$m/$d"
}

Learn about regex

Full Go Interop

Use any Go library. Go imports, Go types, and Go functions work directly in GALA code. One ecosystem, zero friction.

import "strings"

val name = user.Name
    .Map((n) => strings.ToUpper(n))
    .GetOrElse("ANONYMOUS")

Learn about Go interop

IDE Support with LSP

GoLand/IntelliJ plugin with syntax highlighting, type-aware dot completion, inlay type hints, and structure view. LSP server provides diagnostics, hover, go-to-definition, and more.

GALA code completion in IntelliJ

See IDE features

GALA vs Go — A Quick Look

Pattern matching is one of the most visible differences between GALA and Go. Where Go requires a manual type switch with field accessors, GALA destructures values directly and ensures every case is handled at compile time.

GALA

val msg = shape match {
    case Circle(r)       => f"r=$r%.1f"
    case Rectangle(w, h) => f"$w%.0fx$h%.0f"
    case Point()         => "point"
}

Go

var msg string
switch shape._variant {
case Shape_Circle:
    msg = fmt.Sprintf("r=%.1f",
        shape.Radius.Get())
case Shape_Rectangle:
    msg = fmt.Sprintf("%fx%f",
        shape.Width.Get(),
        shape.Height.Get())
case Shape_Point:
    msg = "point"
}

GALA’s version is shorter, handles destructuring automatically, and produces a compile-time error if you forget a case. See the full GALA vs Go comparison for more examples including Option handling, immutable structs, and error handling.

Get Started in 3 Steps

1. Install

Download a pre-built binary from Releases for Linux, macOS, or Windows. Or build from source:

git clone https://github.com/martianoff/gala.git && cd gala
bazel build //cmd/gala:gala

2. Write

Create main.gala:

package main

struct Person(Name string, Age int)

func greet(p Person) string = p match {
    case Person(name, age) if age < 18 => s"Hey, $name!"
    case Person(name, _)               => s"Hello, $name"
}

func main() {
    Println(greet(Person("Alice", 25)))
}

3. Run

gala run main.gala

Or with Bazel for larger projects:

bazel run //myapp:myapp

See the full Getting Started guide for project setup, Bazel integration, and dependency management.

Standard Library

GALA ships with a standard library of type-safe data structures and monads, all built on sealed types and functional programming patterns.

Types

Type Description Documentation
Option[T] Optional values — Some(value) / None() Monadic types
Either[A, B] Disjoint union — Left(a) / Right(b) Monadic types
Try[T] Failable computation — Success(value) / Failure(err) Monadic types
Future[T] Async computation with Map, FlatMap, Zip, Await Concurrency
Tuple[A, B] Pairs and triples with (a, b) syntax Language spec
ConstPtr[T] Read-only pointer with compile-time enforcement Immutability
Codec[T] Zero-reflection JSON codec — Encode, Decode, Rename, Omit, pattern matching JSON codec
Regex Regular expressions with Unapply for pattern matching Regex
IO[T] Lazy composable effects — Of, Suspend, Map, FlatMap IO effect

Collections

Type Kind Key Operations Best for
List[T] Immutable O(1) prepend, O(n) index Recursive processing
Array[T] Immutable O(1) random access General-purpose sequences
HashMap[K,V] Immutable O(1) lookup Key-value storage
HashSet[T] Immutable O(1) membership Unique element collections
TreeSet[T] Immutable O(log n) sorted ops Ordered unique elements
TreeMap[K,V] Immutable O(log n) sorted ops Sorted key-value storage

All collections support Map, Filter, FoldLeft, ForEach, Exists, Find, Collect, MkString, Sorted, and more. Mutable variants are available in collection_mutable for performance-sensitive code. See the collections documentation for details.

Documentation

Document Description
Language Specification Complete reference for GALA syntax and semantics
Getting Started Installation, project setup, and first program
GALA vs Go Side-by-side comparison with idiomatic Go
Sealed Types Algebraic data types and closed hierarchies
Pattern Matching Exhaustive matching, destructuring, and guards
Immutability val, immutable structs, Copy(), and ConstPtr[T]
Error Handling Option[T], Either[A,B], Try[T] monads
Collections Immutable and mutable functional collections
Concurrency Future[T], Promise[T], and ExecutionContext
JSON Codec Zero-reflection JSON serialization with Codec[T]
Regex Pattern matching with regex extractors
IO Effect Lazy, composable side effects
Go Interop Using Go libraries and types from GALA
Playground Try GALA in your browser — no install needed

Showcase Projects

Project Description
GALA Playground Web-based playground — try it live
State Machine Example State machines with sealed types and pattern matching
Log Analyzer Structured log parsing with Go stdlib interop and functional pipelines
GALA Server Immutable HTTP server library with builder-pattern configuration