Introduction
Roc is a statically typed functional programming language created by Richard Feldman (creator of Elm's architecture). It prioritizes fast compilation, fast execution, and a friendly developer experience with helpful error messages and minimal boilerplate.
What Roc Does
- Compiles to native machine code for fast execution
- Provides exhaustive pattern matching and algebraic data types
- Offers a platform system for separating pure logic from side effects
- Delivers fast incremental compilation for rapid feedback
- Produces helpful error messages with suggested fixes
Architecture Overview
Roc uses a unique platform/application split. Applications contain pure business logic while platforms handle I/O and side effects. The compiler is written in Rust and Zig, producing LLVM IR that compiles to native binaries. This architecture enables guaranteed purity in application code while maintaining practical I/O capabilities through the platform layer.
Self-Hosting & Configuration
- Install via the official installer or build from source
- Create a new project with
roc init - Choose a platform (basic-cli, basic-webserver) in your app header
- No build configuration files needed; the app header declares dependencies
- Supports cross-compilation for different target architectures
Key Features
- No runtime exceptions with exhaustive pattern matching
- Platform system cleanly separates pure and effectful code
- Fast incremental compilation with sub-second rebuilds
- Automatic memory management without garbage collection pauses
- Friendly error messages designed for newcomers
Comparison with Similar Tools
- Elm — Browser-only functional language; Roc targets general-purpose native applications
- Haskell — Academic FP language; Roc prioritizes approachability and compilation speed
- Rust — Systems language with ownership; Roc uses automatic memory management
- OCaml — Mature ML family language; Roc offers simpler syntax and better error messages
FAQ
Q: Is Roc ready for production? A: Roc is pre-1.0 and under active development. It is usable for personal projects and experimentation.
Q: What platforms are available? A: basic-cli for command-line tools, basic-webserver for HTTP servers, and community platforms for other use cases.
Q: Does Roc have a package manager? A: Roc uses URL-based dependencies declared in the app header. A centralized registry is planned.
Q: How does memory management work? A: Roc uses automatic reference counting with compile-time optimizations to eliminate most overhead.