https://github.com/martianoff/gala
GALA (Go Alternative LAnguage) -- a modern functional programming language that transpiles to Go. Sealed types, pattern matching, immutability by default, monads (Option, Either, Try, Future), and full Go interop. Built with Go, ANTLR4, Bazel and Claude.
https://github.com/martianoff/gala
algebraic-data-types bazel compiler compilers functional-programming gala go golang immutability language language-design monads pattern-matching programming-language scala sealed-types transpiler type-inference
Last synced: 10 days ago
JSON representation
GALA (Go Alternative LAnguage) -- a modern functional programming language that transpiles to Go. Sealed types, pattern matching, immutability by default, monads (Option, Either, Try, Future), and full Go interop. Built with Go, ANTLR4, Bazel and Claude.
- Host: GitHub
- URL: https://github.com/martianoff/gala
- Owner: martianoff
- License: apache-2.0
- Created: 2026-01-03T09:13:25.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2026-03-07T11:12:32.000Z (16 days ago)
- Last Synced: 2026-03-07T17:45:54.011Z (15 days ago)
- Topics: algebraic-data-types, bazel, compiler, compilers, functional-programming, gala, go, golang, immutability, language, language-design, monads, pattern-matching, programming-language, scala, sealed-types, transpiler, type-inference
- Language: Go
- Homepage:
- Size: 1.53 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- Contributing: CONTRIBUTING.MD
- License: LICENSE
Awesome Lists containing this project
- awesome-programming-languages - GALA - GALA (Go Alternative Language) is a functional programming language that transpiles to Go, adding sealed types, exhaustive pattern matching, immutability by default, monads (Option, Either, Try, Future), and immutable collections. [functional, transpiler, go, pattern-matching] (Uncategorized / Uncategorized)
README
# GALA
[](https://github.com/martianoff/gala/actions/workflows/test.yml)
[](https://github.com/martianoff/gala/releases)
[](https://github.com/martianoff/gala/releases/latest)
[](LICENSE)
[](https://go.dev)
[](https://bazel.build)
[](CONTRIBUTING.MD)
**GALA** (Go Alternative LAnguage) is a modern programming language that transpiles to Go. It brings sealed types, pattern matching, immutability by default, and functional collections to the Go ecosystem -- without sacrificing Go's performance, tooling, or library compatibility.
```gala
sealed type Shape {
case Circle(Radius float64)
case Rectangle(Width float64, Height float64)
}
func area(s Shape) string = s match {
case Circle(r) => fmt.Sprintf("circle area: %.2f", 3.14159 * r * r)
case Rectangle(w, h) => fmt.Sprintf("rect area: %.2f", w * h)
}
```
---
## What is GALA?
GALA transpiles to clean, readable Go code. You get Scala-like expressiveness -- sealed types, exhaustive pattern matching, `Option[T]`/`Either[A,B]`/`Try[T]` monads, immutable collections -- and it compiles to a single native binary. Every Go library works out of the box.
---
## Key Features
**Sealed types and exhaustive pattern matching** -- Define closed type hierarchies. The compiler rejects incomplete matches.
```gala
sealed type Result[T any] {
case Ok(Value T)
case Err(Message string)
}
val msg = result match {
case Ok(v) => fmt.Sprintf("got %d", v)
case Err(msg) => "error: " + msg
}
```
**Immutability by default** -- `val` and `:=` are immutable. Structs auto-generate `Copy()` and `Equal()`.
```gala
struct Config(Host string, Port int)
val updated = config.Copy(Port = 8080)
```
**Expression functions** -- Single-expression functions skip braces and `return`.
```gala
func square(x int) int = x * x
func max(a int, b int) int = if (a > b) a else b
```
**Lambda type inference** -- Parameter types and method type parameters are inferred from context.
```gala
val list = ListOf(1, 2, 3)
val doubled = list.Map((x) => x * 2)
val sum = list.FoldLeft(0, (acc, x) => acc + x)
```
**Monads** -- `Option[T]`, `Either[A,B]`, `Try[T]`, `Future[T]` with `Map`, `FlatMap`, `Recover`, and pattern matching.
```gala
val name = user.Name
.Map((n) => strings.ToUpper(n))
.GetOrElse("ANONYMOUS")
```
**Functional collections** -- Immutable `List`, `Array`, `HashMap`, `HashSet`, `TreeSet`, `TreeMap` with `Map`, `Filter`, `FoldLeft`, `Collect`, and more.
```gala
val nums = ArrayOf(1, 2, 3, 4, 5)
val evens = nums.Filter((x) => x % 2 == 0)
val evenDoubled = nums.Collect({ case n if n % 2 == 0 => n * 2 })
```
**Tuples with destructuring** -- Up to Tuple5, with pattern matching and concise syntax.
```gala
val pair = (1, "hello")
val (x, y) = pair
```
**Read-only pointers** -- `ConstPtr[T]` prevents accidental mutation through pointers.
```gala
val data = 42
val ptr = &data // ConstPtr[int], not *int
val value = *ptr // OK: read
// *ptr = 100 // compile error: cannot write through ConstPtr
```
**Full Go interop** -- Use any Go library.
---
## Quick Start
### 1. Install
Download a pre-built binary from [Releases](https://github.com/martianoff/gala/releases), or build from source:
```bash
git clone https://github.com/martianoff/gala.git && cd gala
bazel build //cmd/gala:gala
```
### 2. Write
```gala
package main
import "fmt"
struct Person(Name string, Age int)
func greet(p Person) string = p match {
case Person(name, age) if age < 18 => "Hey, " + name + "!"
case Person(name, _) => "Hello, " + name
}
func main() {
fmt.Println(greet(Person("Alice", 25)))
}
```
### 3. Run
```bash
gala run main.gala
# Or with Bazel (recommended for projects)
bazel run //myapp:myapp
```
---
## GALA vs Go
### Pattern Matching vs Switch
GALAGo
```gala
val msg = shape match {
case Circle(r) => fmt.Sprintf("r=%.1f", r)
case Rectangle(w,h) => fmt.Sprintf("%fx%f", w, h)
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"
}
```
### Option Handling vs nil Checks
GALAGo
```gala
val name = user.Name
.Map((n) => strings.ToUpper(n))
.GetOrElse("ANONYMOUS")
```
```go
name := "ANONYMOUS"
if user.Name != nil {
name = strings.ToUpper(*user.Name)
}
```
### Immutable Structs vs Manual Copying
GALAGo
```gala
struct Config(Host string, Port int)
val updated = config.Copy(Port = 8080)
```
```go
type Config struct {
Host string
Port int
}
updated := Config{Host: config.Host, Port: 8080}
```
### Error Handling: Try vs if-err
GALAGo
```gala
val result = divide(10, 2)
.Map((x) => x * 2)
.FlatMap((x) => divide(x, 3))
.Recover((e) => 0)
```
```go
result, err := divide(10, 2)
if err != nil {
result = 0
} else {
result = result * 2
result, err = divide(result, 3)
if err != nil {
result = 0
}
}
```
---
## Standard Library
### Types
| Type | Description |
|------|-------------|
| `Option[T]` | Optional values -- `Some(value)` / `None()` |
| `Either[A, B]` | Disjoint union -- `Left(a)` / `Right(b)` |
| `Try[T]` | Failable computation -- `Success(value)` / `Failure(err)` |
| `Future[T]` | Async computation with `Map`, `FlatMap`, `Zip`, `Await` |
| `Tuple[A, B]` | Pairs and triples with `(a, b)` syntax |
| `ConstPtr[T]` | Read-only pointer with auto-deref field access |
### Collections
| Type | Kind | Key Operations | Best for |
|------|------|----------------|----------|
| `List[T]` | Immutable | O(1) prepend, O(n) index | Recursive processing, prepend-heavy workloads |
| `Array[T]` | Immutable | O(1) random access | General-purpose indexed sequences |
| `HashMap[K,V]` | Immutable | O(1) lookup | Functional key-value storage |
| `HashSet[T]` | Immutable | O(1) membership | Unique element collections |
| `TreeSet[T]` | Immutable | O(log n) sorted ops | Ordered unique elements, range queries |
| `TreeMap[K,V]` | Immutable | O(log n) sorted ops | Sorted key-value storage, range queries |
All collections support `Map`, `Filter`, `FoldLeft`, `ForEach`, `Exists`, `Find`, `Collect`, `MkString`, `Sorted`, `SortWith`, `SortBy`, and more.
`TreeMap[K,V]` is a Red-Black tree that maintains entries in sorted key order. It provides `MinKey`, `MaxKey`, `Range(from, to)`, `RangeFrom`, `RangeTo`, and conversion to `HashMap`, Go maps, or sorted arrays.
Mutable variants of all collection types are available in `collection_mutable` for performance-sensitive code.
---
## Dependency Management
```bash
gala mod init github.com/user/project
gala mod add github.com/example/utils@v1.2.3
gala mod add github.com/google/uuid@v1.6.0 --go
gala mod tidy
```
---
## IDE Support
### IntelliJ IDEA
```bash
bazel build //ide/intellij:plugin
# Install bazel-bin/ide/intellij/gala-intellij-plugin.zip via Settings > Plugins
```
Features: syntax highlighting, code completion, brace matching, code folding.
---
## Installation
### Pre-built Binaries
Download from [Releases](https://github.com/martianoff/gala/releases):
| Platform | Binary |
|----------|--------|
| Linux (x64) | `gala-linux-amd64` |
| Linux (ARM64) | `gala-linux-arm64` |
| macOS (x64) | `gala-darwin-amd64` |
| macOS (Apple Silicon) | `gala-darwin-arm64` |
| Windows (x64) | `gala-windows-amd64.exe` |
### Build from Source
```bash
git clone https://github.com/martianoff/gala.git
cd gala
bazel build //cmd/gala:gala
```
### Using Bazel (Recommended)
```python
load("//:gala.bzl", "gala_binary", "gala_library")
gala_binary(
name = "myapp",
src = "main.gala",
)
```
---
## Documentation
- [Language Specification](docs/GALA.MD) -- Complete language reference
- [Why GALA?](docs/WHY_GALA.MD) -- Feature deep-dive and honest trade-offs
- [Examples](docs/EXAMPLES.MD) -- Code examples for all features
- [Type Inference](docs/TYPE_INFERENCE.MD) -- How type inference works
- [Concurrent](docs/CONCURRENT.MD) -- Future, Promise, and ExecutionContext
- [Stream](docs/STREAM.MD) -- Lazy, potentially infinite sequences
- [Immutable Collections](docs/IMMUTABLE_COLLECTIONS.MD) -- List, Array, HashMap, HashSet, TreeSet, TreeMap
- [Mutable Collections](docs/MUTABLE_COLLECTIONS.MD) -- Mutable variants for performance
- [String Utils](docs/STRING_UTILS.MD) -- Rich string operations
- [Time Utils](docs/TIME_UTILS.MD) -- Duration and Instant types
- [Dependency Management](docs/DEPENDENCY_MANAGEMENT.MD) -- Module system
---
## Contributing
Contributions are welcome. Please ensure:
1. `bazel build //...` passes
2. `bazel test //...` passes
3. New features include examples in `examples/`
4. Documentation is updated for grammar/feature changes
---
## License
[](LICENSE)
Apache License 2.0. See [LICENSE](LICENSE) for details.