Safari Ride: a tour of a real Roc program
Safari Ride is a small Roc program with a lot to look at. In this book, we read it with you.
Contents
- The big picture
- 1Introduction
- Run it yourself
- 2One page
- 3The problem
- 4Platforms, packages and modules
- 5Types
- Distance pins down a number
- A billboard spells out its fields and its choices
- Plain records lay out the road
- A type variable carries every kind
- One record captures the whole ride
- The tour keeps the past
- Types come first
- 6Functions
- A function is a value
- A body is one expression
- An annotation states the contract
- A method belongs to its type
- Every function has this shape
- One frame
- 7Things
- A billboard stands in for an animal
- A species record names the animal
- A function picks the calves
- Every kind returns a sprite
- 8Tag unions: billboard critters
- A tag union lists every case
- A match handles every case
- A nominal type sets its tags apart
- A tag carries a value
- Elephants, mostly
- 9Shapes
- A triangle
- A rectangle
- 10Lists and map: a far tree
- Eight tiers
- Tops and bottoms
- Freezing the tiers
- A triangle for each tier
- Painting the tree
- What you're missing
- 11The pipeline
- Placed
- Sighted
- Rendered
- One list
- 12Where clauses: asking a kind
- A kind from the inside
- One function for every kind
- The compiler checks each call
- Asking for a height
- Names that say what they're for
- 13Errors as tag unions
- An answer that can fail
- A test on top
- Where the refusals stop
- Try or crash
- Nature
- 14The sky and the grass
- The top of the sky
- The horizon
- The fade
- The grass
- 15Mountains
- Directions
- A range
- Across the screen
- Back to front
- Man-made
- 16The road
- A segment's ground
- Along a segment
- At a bend
- 17Rails
- From path to quads
- Bars and posts
- 18Radio towers
- Where a tower stands
- Over the horizon
- Rods
- Critters that stand still
- 19Herds
- Cows
- Pigs
- Motion
- 20Immutable values: a flip book
- Turning back
- What a moment holds
- 21Records
- 22Pure functions and effects
- The keys
- 23Opaque types: the clock
- A moment and a length
- The module
- Two invariants
- Tests
- 24The ride instant
- One step
- Carried and derived
- The passage of time
- 25The beacons
- Three rules
- Which beacon, and when
- The phase
- The brightness
- A disc, or a refusal
- 26The setting sun
- The sun goes down
- In view, or out of view
- The sky darkens
- The horizon warms
- Going backward
- Vehicles
- 27The rider
- The rider's step
- Deciding
- One step of physics
- The end of a segment
- The picture leans too
- 28The throttle
- 29Variables and loops: rehearsal
- Where the rehearsals start
- A coast
- Twelve tries
- Why rehearsing is safe
- 30The rider's gaze
- Get the types right
- The look
- Turning the head
- The depth of a look
- Gawking
- The first pig
- 31The truck
- The whole job
- The body's shape
- Shape, placement, projection
- The headlights
- The brake lights
- 32The truck's motion
- A tease, carried out by physics
- Carried from step to step
- Get the types right
- The functions
- Critter motion
- 33The cat
- One step carried
- When it starts
- Where it has got to
- What it looks like
- A timeline
- Into the frame
- 34The bird
- The same plan
- Its poses
- Its path
- Finding its trees
- Into the frame
- 35What a cat does to the rider
- Hold the throttle
- Look
- Under the hood
- 36The math layer
- Round the bends
- To the rider
- Through the pinhole
- Cutting at the near plane
- 37Proving it
- A fixture is a value
- The frame hash
- Sums in order
- Three more proofs
- Tests beside the code
- Crashes that check
- The page itself
- 38The platform
- An app is a value
- What the platform calls
- The person watching
- The host
- A frame is a list
- 39Zooming back out
- Four things carried
- One step, in order
- Where each thing comes from
- Appendices
- Appendix: the patterns
- Appendix: list functions
- Appendix: what catches you out
- Appendix: glossary
- Appendix: index
- Roc concepts
- Animation concepts
- Safari Ride's design
- Credits