A fast, friendly, functional language.
credits = List.map songs \song -> "Performed by $(song.artist)"
You can try Roc using this read-eval-print loop (REPL), which is running in your browser in WebAssembly.
Shift-Enter adds a newline.
Try entering 0.1 + 0.2
Enter an expression to evaluate, or a definition (like x = 1) to use later.
main = Stdout.line! "Hello!"
You can use Roc to create scripts and command-line interfaces (CLIs). The compiler produces binary executables, so Roc programs can run on devices that don't have Roc itself installed.
As an example, the HTML for this website is generated using a simple Roc script. You can see the code for it in the main Roc code repository.
If you’re looking for a starting point for building a command-line program in Roc, basic-cli is a popular platform to check out.
handleReq = \request -> Task.ok { body: … }
You can also build web servers in Roc. basic-webserver is a platform with
a simple interface: you write a function which takes a Request, does some I/O, and returns a Response.
Behind the scenes, it uses Rust's high-performance hyper and tokio libraries to execute your Roc function on incoming requests.
For database access, roc-pg lets you access a PostgreSQL database—with your Roc types checked against the types in your database's schema.
fn = require("foo.roc"); log(`Roc says ${fn()}`);
You can call Roc functions from other languages. There are several basic examples of how to call Roc functions from Python, Node.js, Swift, WebAssembly, and JVM languages.
Any language that supports C interop can call Roc functions, using similar techniques to the ones found in these examples.
Most of those are minimal proofs of concept, but roc-esbuild is a work in progress that's used at Vendr to call Roc functions from Node.js.