DEV Community

Alex Spinov
Alex Spinov

Posted on

Roc Has a Free API: The Fast Functional Language Designed for App Developers

Roc is a functional programming language focused on speed, simplicity, and friendliness. It compiles to machine code via LLVM, has no runtime exceptions, and is designed to be the 'fast functional language for app developers' — not academics.

Why Roc?

  • Fast — compiles to native code via LLVM
  • No runtime exceptions — everything handled via Result/Tag unions
  • Platform system — separate pure logic from I/O effects
  • Great errors — compiler messages are paragraphs, not cryptic codes
  • Simple — no type classes, no monads, no macros

Install

# Download (nightly)
curl -sSfL https://github.com/roc-lang/roc/releases/latest/download/roc_nightly-linux_x86_64-latest.tar.gz | tar xz

# Or build from source
git clone https://github.com/roc-lang/roc.git
cd roc && cargo build --release
Enter fullscreen mode Exit fullscreen mode

Hello World

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }

import pf.Stdout

main =
    Stdout.line! \"Hello from Roc!\"
Enter fullscreen mode Exit fullscreen mode
roc run hello.roc
Enter fullscreen mode Exit fullscreen mode

Core Language

# Records
user = { name: \"Alice\", age: 30, email: \"alice@example.com\" }

# Tag unions (like Rust enums)
Color : [Red, Green, Blue, Custom Str]

describe : Color -> Str
describe = \\color ->
    when color is
        Red -> \"The color red\"
        Green -> \"The color green\"
        Blue -> \"The color blue\"
        Custom name -> \"Custom: $(name)\"

# Pattern matching
result : Result I64 [DivByZero]
result =
    when divisor is
        0 -> Err DivByZero
        n -> Ok (dividend // n)

# Pipelines
numbers =
    [1, 2, 3, 4, 5]
    |> List.map (\\x -> x * 2)
    |> List.keepIf (\\x -> x > 4)
    |> List.sum
Enter fullscreen mode Exit fullscreen mode

Web Server (basic-webserver platform)

app [main] { pf: platform "https://github.com/roc-lang/basic-webserver/..." }

import pf.Http exposing [Request, Response]
import pf.Task exposing [Task]

main : Request -> Task Response []
main = \\req ->
    when req.url is
        "/" -> Task.ok { status: 200, headers: [], body: Str.toUtf8 \"Welcome to Roc!\" }
        "/api/users\" -> Task.ok {
            status: 200,
            headers: [(\"Content-Type\", \"application/json\")],
            body: Str.toUtf8 \"[{\\\"name\\\": \\\"Alice\\\"}]\"
        }
        _ -> Task.ok { status: 404, headers: [], body: Str.toUtf8 \"Not found\" }
Enter fullscreen mode Exit fullscreen mode

Platform System

+-------------------+     +--------------------+
|   Your App        |     |   Platform         |
|   (Pure Logic)    | <-> |   (I/O Effects)    |
|   No side effects |     |   File, Network,   |
|   Testable        |     |   Stdout, HTTP     |
+-------------------+     +--------------------+
Enter fullscreen mode Exit fullscreen mode

Platforms provide: CLI, Web Server, WASM, GUI, embedded — your app logic stays pure.

Key Features

Feature Details
Typing Static, inferred, no annotations needed
Compilation LLVM → native machine code
Error handling Result types, tag unions
Immutability Everything immutable by default
Platforms CLI, Web, WASM, custom
Package manager Built-in

Resources


Exploring modern languages? I build custom tools and data pipelines. Check my Apify actors or email spinov001@gmail.com.

Top comments (0)