Roc is a fast, friendly, functional language.
basic-cli also offers the network, environment variables, standard input and the clock. The
programs here need only what's listed above.
The platform's README explains how
it works.
The examples are in sections. The first holds programs that find flaws in Roc code, and some that
fix them too: Roc reading Roc, most of them through Roc's own parser. After it come programs that read Shale itself, then reports on Roc
projects, then smaller programs over Zig. The shared packages the examples import are listed at the end, and each
is shown once, on a page of its own.
Shale is also a scripting language of its own, and each example began as a Shale script. Each
example's page shows its Roc program, then the Shale script it was ported from, with both files colored by
roc-syntax-color. Each port was checked against its original's output. The links at
the top and end of each example's page go to the one before or after it, and back to its place here.
The Roc platform's host is that same C, with a small driver added. It's compiled once with
gcc -O2 into an object and cached. Each Roc script is built by the pinned Roc compiler into an archive
and linked with that object, and the program is cached by a hash of every file it's built from. The Roc runs on a
stack of its own, takes its memory from an arena held to the run's budget, and has a CPU budget for its own
computation.
The checks that Steve's Roc repositories run in their gates, ported from Shale to Roc, so each one is Roc code reading Roc code, most of them through Roc's own parser.
A gate over Roc's own parse trees for names and module docs that say too little: a pure function named like a mutation, an abbreviation, a missing or historical doc.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.re_lines!, Shale.re_replace!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 727 lines in 5 files. Shale original: 372 lines, plus 1,374 lines in the 6 libraries it loads, which other recipes share.
The import lines a Roc file never uses, read from Roc's own parse tree, a gate with its plants' self-test in Roc too.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_lines!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 263 lines in 2 files. Shale original: 106 lines, plus 261 lines in the 4 libraries it loads, which other recipes share.
Each Roc module held to a size, the whole file counted, written line for line beside its Shale original, which is still the recipe (the commit is the one that added the Roc).
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.read!.
Roc: 219 lines in 1 file. Shale original: 206 lines, plus 21 lines in the library it loads, which other recipes share.
Modules that look alike but are spelled unlike, one type name declared in two shapes, and a conversion into a type not named from_, read from Roc's own parse trees across a whole tree, a gate with its plants' self-test in Roc too.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_lines!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 727 lines in 5 files. Shale original: 183 lines, plus 1,328 lines in the 5 libraries it loads, which other recipes share.
Calls nested three or more deep, read inside out, found from Roc's own parse tree: each node's call depth worked out from its kids, the outermost call of each nest reported with the call at its bottom.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.read!, Shale.roc_tree!.
Roc: 658 lines in 4 files. Shale original: 232 lines, plus 101 lines in the 3 libraries it loads, which other recipes share.
A project held to the words it has decided on: each identifier, read from Roc's own parse tree, and each comment that holds a word the project's words file retires, a gate with its plants' self-test in Roc too.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.re_lines!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 605 lines in 5 files. Shale original: 209 lines, plus 1,232 lines in the 4 libraries it loads, which other recipes share.
Names that disagree with their types, read from Roc's own parse trees across a whole tree: a name ending in a word the project's table types otherwise, a bare number beside a unit of the same field name, a constant that means none but holds an ordinary value.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.re_lines!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 748 lines in 6 files. Shale original: 207 lines, plus 1,232 lines in the 4 libraries it loads, which other recipes share.
Every bare F64 in a project's declarations, read from Roc's own parse trees and judged against the project's table of named exceptions, sparing the helpers only tests use, a gate with its plants' self-test in Roc too.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.re_lines!, Shale.read!, Shale.roc_tree!, Shale.run!.
Roc: 814 lines in 5 files. Shale original: 300 lines, plus 1,232 lines in the 4 libraries it loads, which other recipes share.
The parentheses and braceless ifs a code emitter leaves in Roc, found from Roc's own parse trees and, with write=1, taken off by the parser's spans and put through roc fmt until a pass changes nothing, its self-test rewriting copies of its plants.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.mkdir!, Shale.print!, Shale.re_find!, Shale.read!, Shale.real!, Shale.remove_tree!, Shale.roc_tree!, Shale.run!, Shale.write!.
Roc: 985 lines in 6 files. Shale original: 442 lines, plus 121 lines in the 4 libraries it loads, which other recipes share.
How Roc code reports failure, read from Roc's own parse trees and, when asked, Roc's own type checker: an error named by a shared alias of tags, a tag named like an optional, and a ?? that falls back to the list it stores into, a placeholder string or a number after an index.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.read!, Shale.real!, Shale.roc_tree!, Shale.run!.
Roc: 895 lines in 6 files. Shale original: 462 lines, plus 376 lines in the 4 libraries it loads, which other recipes share.
Groups laid out against the stacking rule, both ways, and lines past the width, read a byte at a time by the Roc library's Groups and Stacking, with write=1 adding and taking trailing commas for roc fmt until a pass changes nothing.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.mkdir!, Shale.print!, Shale.re_find!, Shale.read!, Shale.real!, Shale.remove_tree!, Shale.roc_tree!, Shale.run!, Shale.write!.
Roc: 1,208 lines in 5 files. Shale original: 610 lines, plus 681 lines in the 6 libraries it loads, which other recipes share.
Awkward names hunted across a whole tree from Roc's own parse trees and, when asked, its type checker: an effect named like a state, a question that gives no Bool, tense in tags, container words, a one-word where method, a pure function named to act outside, and docs naming what is gone.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.re_find!, Shale.re_find_all!, Shale.re_match!, Shale.read!, Shale.real!, Shale.roc_tree!, Shale.run!.
Roc: 3,247 lines in 13 files. Shale original: 718 lines, plus 1,999 lines in the 10 libraries it loads, which other recipes share.
Whether each function's boundary earns its keep and each parameter is really one, from Roc's own parse trees across a tree: a one-caller wrapper, a parameter every call fills with the same literal, a constant written as a function, dead code, alike branches and, with the types, a Bool flag passed as a literal.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.read!, Shale.real!, Shale.roc_tree!, Shale.run!.
Roc: 1,592 lines in 7 files. Shale original: 830 lines, plus 497 lines in the 5 libraries it loads, which other recipes share.
Long Roc lines shortened and groups laid out by the stacking rule, through trailing commas that roc fmt reads, on a work copy pass after pass until nothing changes, by the Roc library that is now the rule's one home, the lines left wide listed after.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.mkdir!, Shale.print!, Shale.re_find!, Shale.re_replace!, Shale.read!, Shale.real!, Shale.remove_tree!, Shale.roc_tree!, Shale.run!, Shale.write!.
Roc: 730 lines in 4 files. Shale original: 405 lines, plus 540 lines in the 4 libraries it loads, which other recipes share.
Old-style calls such as List.map(xs, f) rewritten as method calls where Roc's own type checker proves the first argument the module's own type or the compiler, trial by trial, accepts the rewrite with roc test unchanged, each call that stays given its reason and each file a failed trial touched put back byte for byte.
Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.list!, Shale.mkdir!, Shale.print!, Shale.re_find!, Shale.read!, Shale.real!, Shale.remove_tree!, Shale.roc_tree!, Shale.run!, Shale.write!.
Roc: 2,846 lines in 15 files. Shale original: 1,195 lines, plus 888 lines in the 7 libraries it loads, which other recipes share.
Programs that work on Shale itself: how an agent's Shale launches ended, read from a Claude Code transcript, and Shale's own C, split into functions by a splitter written in Roc.
How an agent's Shale launches went, from a Claude Code transcript: each Bash call paired with its answer, every line's JSON read in Roc as Shale's own json_read reads it, and the stops grouped by kind and by message.
Its effects: Shale.arg!, Shale.fail!, Shale.grep_all!, Shale.print!, Shale.re_find!, Shale.re_find_all!, Shale.re_match!, Shale.re_replace!.
Roc: 1,123 lines in 5 files. Shale original: 164 lines.
A file of Shale's C mapped, one line an item, by the splitter in Roc that reads the C's dialect with no parser: a masker, a line reader and its regular expressions done by hand.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 377 lines in 2 files. Shale original: 192 lines, plus 499 lines in the library it loads, which other recipes share.
Shale's C functions past a length in lines of code, their comment and blank lines counted apart, past the tree's 95th percentile unless told, with the distribution first.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 314 lines in 3 files. Shale original: 143 lines, plus 499 lines in the library it loads, which other recipes share.
Shale's C functions ranked by how deeply their braces nest, each body line read through the splitter's masker so a brace in a string or a comment is none.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 312 lines in 3 files. Shale original: 156 lines, plus 499 lines in the library it loads, which other recipes share.
The same code twice in Shale's C: twin functions of one shape once every name, number and string is masked, scored by Dice's coefficient, and runs of lines alike as written.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 666 lines in 4 files. Shale original: 327 lines, plus 499 lines in the library it loads, which other recipes share.
The functions and generators in Shale's C that no program reaches, and those only the tests reach: every item a node, its masked words its edges, walked from each program's main and the tests.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 461 lines in 3 files. Shale original: 277 lines, plus 503 lines in the library it loads, which other recipes share.
Names in Shale's C that say too little or the wrong thing, from the splitter's items: each case rule, Zig's bound words, vague words alone, and an abbreviation the tree also spells out, its two regular expressions done by hand in their matcher's order.
Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.list!, Shale.print!, Shale.read!.
Roc: 906 lines in 6 files. Shale original: 319 lines, plus 503 lines in the library it loads, which other recipes share.