Chapter 1
Introduction
Safari Ride is running in the page below. It's a big page, so give the ride a little while to load. Then it starts by itself.
Watch it all the way through. A motorcycle carries its rider down a long country road. Cows and pigs graze in the fields, and trees crowd the roadside. A truck runs on ahead. A cat waits by the road for its moment to cross, and a bird takes off as the rider comes near. As the sun sets behind the mountains, the truck turns on its headlights. At the end of the road the rider stops, and the ride starts over.
Safari Ride is written in Roc, and this is a book about Roc. If you're brand new to Roc, the official Roc tutorial makes a quick first stop. The tutorial teaches the language through small examples. This book picks up from there, with one real program: how its code is organized across many modules, and how Roc's larger ideas, such as opaque types, type variables and where clauses, solve the problems the ride poses. The book quotes the real code behind what's on the screen. The book explains each new Roc idea where the code first needs it.
You'll learn two things as you read: Roc, and how a ride like this one is animated. The animation is a handful of plain ideas. Each frame is one picture, and a step moves the world on before the next. Far things look small, and near things cover far ones. The book explains each of these in plain words where the ride first needs it. A chapter near the end gives the trigonometry behind them. If both are new to you, you'll get both at a walking pace.
Run it yourself §
Safari Ride is open source, in the canvas_apps/safari folder of roc-apps. It builds with the Roc nightly that the repository's roc-version file names, nightly-2026-11-03-34bd006. With that installed, two commands check the whole ride and run its tests:
cd canvas_apps/safari
roc check web.roc
roc test web.roc
roc check checks the type of every value in every module the ride uses, and roc test runs the 645 expect tests those modules hold. Then break something on purpose. In Billboard.roc, delete the FacesRight => Mirrored line from the match in scenery_sprite, and run roc check web.roc again. The compiler names the missing case, as the “Tag unions: billboard critters” chapter shows. Put the line back, and the check passes again.