Skip to content
Macho0xPublic

About

Goop Lang: OCaml-style safety on Go’s runtime.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Goop banner

CI status Latest release License

Goop

OCaml-style safety on Go’s runtime.

Exhaustive ADTs · branded IDs · maps · Go interop · same binaries and stdlib

Try Goop in the browser →
Playground: check, compile, and copy generated Go — no install

Editors: VS Code · Zed · Neovim · Helix

At a glance

Goal Command
Type-check one file (fast) goop check main.goop
Build a runnable binary goop build main.goop → ./goop-out
See generated Go goop compile --stdout main.goop
Run *_test.goop in a folder goop test tests/
New project goop new myapp

Install: curl -fsSL …/scripts/install.sh \| bash or cd src && go build -o ../goop ./cmd/goop. Set GOOP_HOME (cache for builds and .gosig stubs); defaults under your home dir if unset.

Goop in practice

Sum types you can trust — every variant must be handled:

type OrderAck =
  | Filled of { order_id: string; qty: int }
  | Rejected of { reason: string }

let describe (ack: OrderAck) : string =
  match ack with
  | Filled { order_id; qty } -> order_id ^ " filled " ^ int_to_string qty
  | Rejected { reason } -> "rejected: " ^ reason

Branded IDs — order_id and symbol are not interchangeable strings:

type order_id = | Order_id of string
type symbol = | Symbol of string

let place (sym: symbol) (oid: order_id) : string =
  "placed"

let main () =
  println (place (Symbol "ETH-USD") (Order_id "ord-1"))

Maps + option — lookups are Some / None, not “did I check ok?”:

let main () =
  let prices : map[string] int = Map.make () in
  let _ = Map.add prices "ETH" 3200 in
  match Map.get prices "ETH" with
  | Some px -> println (int_to_string px)
  | None -> println "missing"

Go when you need it — import packages, or drop in inline Go / C:

import go "strings"

@[go] {
  func greet(name string) string {
    return "Hello, " + name + "!"
  }
}
val greet : string -> string

@[c] {
  int c_add(int a, int b) { return a + b; }
}
val c_add : int -> int -> int

let main () =
  begin
    println (strings.ToUpper "goop");
    println (greet "world");
    println (int_to_string (c_add 40 2))
  end

Safe

Go lets these slip through. Goop stops them at compile time.

Forgot a match case

type Severity = | Low | High | Critical

let should_alert (s: Severity) : bool =
  match s with
  | Low -> false
  | High -> true
✕ EXHAUST003: non-exhaustive match: missing constructor(s): Critical
╭─[example.goop:4:3]
  3 │ let should_alert (s: Severity) : bool =
> 4 │   match s with
  ·   ╰── EXHAUST003: non-exhaustive match: missing constructor(s): Critical
  5 │   | Low -> false
╰────

Forgot None

let greet (name: string option) : string =
  match name with
  | Some n -> "hi, " ^ n
✕ EXHAUST003: non-exhaustive match: missing constructor(s): None
╭─[example.goop:3:3]
  2 │ let greet (name: string option) : string =
> 3 │   match name with
  ·   ╰── EXHAUST003: non-exhaustive match: missing constructor(s): None
  4 │   | Some n -> "hi, " ^ n
╰────

Quick reference

One canonical surface, no surprises. The right column runs as Go.

Goop Go
let add (a: int) (b: int) : int = a + b func Add(a, b int) int { return a + b }
type color = Red | Green | Blue tagged interface + type switch
match c with | Red -> "r" | _ -> "other" exhaustive — compiler rejects a missing arm
let x = Some 42 in match x with | Some n -> n | None -> 0 option, not null
("ok", "err") result + Ok / Error (T, error) — Goop makes it a result
let r = ref 0 in r := !r + 1 & / * behind safe syntax
for i = 0 to n - 1 do ... done for i := 0; i < n; i++
while cond do ... done for cond { ... }
let m : map[string] int = Map.make () map[string]int
[1; 2; 3], x :: xs, List.map / filter / fold / find slices + helpers
Array.make n v, arr.(i) <- v make([]T, n)
import go "strings" uses strings directly
@[go] { … } / @[c] { … } inline Go / cgo
exception E of string, try … with panic + recover
effect E, perform, match … | effect (E _) k -> CPS-lowered handlers

Full surface: syntax · type system · builtins.

Testing your code

A Goop test is a normal module named *_test.goop with let main () = … and assert checks. goop test <dir> finds every *_test.goop in that directory, compiles each to a small Go program, builds it, and runs it (exit 0 = pass).

goop test tests/          # run the whole integration corpus
goop check tests/foo_test.goop   # parse + types only (seconds)
// tests/example_test.goop
module ExampleTest

let main () =
  begin
    assert (1 + 1 = 2);
    match Some 41 with
    | Some n -> assert (n + 1 = 42)
    | None -> assert false
  end

This repo has 166 such files (syntax, Go FFI, inline C, std modules). CI runs the same suite from src/ after warming stubs:

cd src && go build -o /tmp/goop ./cmd/goop
export GOOP_HOME="${TMPDIR:-/tmp}/goop-home" && mkdir -p "$GOOP_HOME"
/tmp/goop gen-sig --smoke && /tmp/goop gen-sig strings os path/filepath
/tmp/goop test ../tests/

Why isn’t goop test instant? Each file gets its own scratch module: codegen → go mod tidy → go build → run. There is no shared test binary and no parallelism yet, so a full directory run is an integration pass (often 30–60 minutes on a laptop). Running several goop test processes at once also fights the Go build cache and can look “stuck” for hours — use one runner. For day-to-day work, prefer goop check on the file you are editing.

Getting started

Playground (fastest)

Open the playground — type Goop, run check/compile in the browser, copy generated Go. No install, no local toolchain.

Install locally

# One-line install (latest release binary)
curl -fsSL https://raw.githubusercontent.com/Macho0x/Goop/main/scripts/install.sh | bash

# Or build from source
cd src && go build -o ../goop ./cmd/goop
../goop new hello && cd hello
../goop check main.goop
../goop build main.goop   # → ./goop-out
./goop-out

Show what the compiler emits (no cache write):

goop compile --stdout docs/examples/hello.goop

Generated Go stays under $GOOP_HOME/build by default (unless --stdout or --in-tree). Lowering is one-way — there is no Go → Goop auto-translator. Teaching pairs: docs/examples/gallery/. Tutorial (maps) · CLI artifacts · maps.goop · branded_ids.goop

How Goop compares

Compile-time checks Go leaves to tests or panics — without giving up Go’s runtime.

Go Rust OCaml Goop
Sum types + exhaustive match ❌ ✅ ✅ ✅
No null by default (option) ❌ ✅ ✅ ✅
Recoverable errors as result ❌ (error) ✅ ✅ ✅
Branded / nominal IDs ❌ ✅ ✅ ✅
First-class maps ✅ ✅ ✅ ✅
Effect handlers (OCaml 5-style) ❌ ❌ ✅ ✅
Nil-channel / close safety ❌ (runtime) N/A N/A ✅
Data-race awareness ⚠️ -race ✅ ❌ ✅ (conservative)
Refinement contracts ❌ ⚠️ ⚠️ ✅ (optional Z3)
Inline Go embeds (@[go]) — ❌ ❌ ✅
Inline C / cgo (@[c]) ✅ ❌ ❌ ✅
Native Go stdlib + deploy ✅ ❌ ❌ ✅
Compiles to ordinary Go binaries — ❌ ❌ ✅

STYLE.md · extern_demo.goop · cgo_demo.goop

Status

v1.24.0 — 166 integration tests, README CLI/testing guide. Playground is still the fastest way to try Goop without installing.

CHANGELOG · RELEASE_NOTES · Benchmarks · Language-update checklist

FAQ

Production-ready? Compiler, checker, codegen, LSP, and CI e2e ship today. We are not claiming production load readiness yet.

Need OCaml or Z3? No. Pattern matching from Rust/Swift/Kotlin transfers. Z3 is optional ([check] smt = true).

Tests hung or very slow? See Testing your code: one goop test at a time, warm gen-sig like CI, and use goop check while iterating. A missing while increment or a bad import go + callback combo can hang a single test until you fix the source.

Documentation

Playground Try Goop in the browser (check, compile, copy Go)
Tutorial Getting started through maps
Stdlib Prelude and std.*
Examples Checked in CI
Goop ↔ Go gallery Hand-written teaching pairs (not a translator)
Writing tools Files + maps via import go
Language-update checklist Required sweep after language changes
Contributing Build and test

License

MIT / Apache-2.0 dual license.

About

Goop Lang: OCaml-style safety on Go’s runtime.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages