Steve's Roc Workroc-syntax-colorShale on GitHub

Roc on Shale

The programs listed here are written in Roc and run on Shale, a runtime for programs that work with files, folders and other programs. Each is a check or a report we run on our own code, and each has a page of its own that shows it in full.

What Roc brings

Roc is a fast, friendly, functional language.

Effects come from a platform

Every Roc application runs on a platform, which supplies its effects: reading files, reaching the network and the rest. A program has only the effects its platform offers. basic-cli, Roc's standard platform for command-line programs, offers a wide set: files and folders, the network, environment variables, the clock and more. The platform these examples use offers a narrower set, adds a few things of its own, and has Shale's runtime as its host, so each effect is a call into Shale, held to the limits Shale sets for the run. Everything else is plain Roc.

platform cluster_roc Roc program the program pure functions, expects api Shale.roc the platform's functions program->api calls rules Shale's runtime, the host budgets · root · rules · timeouts api->rules each effect files files and folders rules->files programs other programs rules->programs parser Roc's parser, regex rules->parser

What it offers

What it adds

Beyond this platform

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

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's own language

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.

How the runtime is built

Shale's runtime is written in C, in its repository's c/ folder, and needs only Linux on x86-64, GCC and TCC.

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.

Finding and fixing flaws in Roc code

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.

find_names_and_docs_that_say_too_little

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.

find_unused_imports

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.

check_modules_stay_under_500_lines

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.

find_names_that_differ_across_lookalike_modules

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.

find_calls_nested_three_deep

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.

find_retired_words

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.

find_names_that_disagree_with_their_types

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.

find_floats_outside_unit_types

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.

find_and_remove_extra_parentheses

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.

check_how_failure_is_reported

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.

check_and_fix_group_stacking

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.

find_awkward_names

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.

find_functions_and_parameters_that_dont_earn_their_keep

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.

wrap_long_lines_with_trailing_commas

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.

rewrite_module_calls_as_method_calls

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 read Shale itself

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.

count_shale_stops

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.

map_file

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.

list_long_functions

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.

list_deep_nesting

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.

find_clones

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.

find_dead_code

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.

hunt_names_c

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.

Reports on Roc projects

A report to read rather than a gate to pass: what a tree of Roc projects holds, counted.

count_roc_modules_lines_and_tests

A test-density report for a tree of Roc projects: each folder's modules and lines, its test modules and lines, and its expects, where roc loc gives one app's size.

Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.read!.
Roc: 240 lines in 1 file. Shale original: 55 lines.

Small scripts over Zig

Smaller ports that read Zig files rather than Roc: a walk, a sort and a table, and a line-by-line scan with its patterns in plain Roc.

list_long_files

The .zig files over a thousand lines in the repos we work in, longest first: the smallest walk, a sort and a table.

Its effects: Shale.arg!, Shale.fail!, Shale.glob!, Shale.print!, Shale.read!.
Roc: 96 lines in 1 file. Shale original: 20 lines.

count_comments

How much each Zig file's comments say and how loudly: each trimmed line a tag (blank, code, doc, plain), per-file ratios, and the regular expressions done as byte patterns in plain Roc.

Its effects: Shale.arg!, Shale.exists!, Shale.fail!, Shale.glob!, Shale.print!, Shale.read!.
Roc: 477 lines in 1 file. Shale original: 96 lines.

The shared Roc library

The modules the ports over Roc code share, as a package each app names in its header and imports as lib.X: Roc's parse tree read into records, a file's lines and words, a module's declarations, and a finding's line. Each example that imports it names the modules it uses.

The shared Roc library: 13 files

The C splitter

The package the programs over Shale's C share, imported as items.X: it blanks strings and comments, then splits a file into its top-level items, each with its kind, name, lines, head and body. Each example that imports it names the modules it uses.

The C splitter: 8 files