Skip to contentVarnook
All courses
HollowScriptIntermediate

Intermediate HollowScript

Go beyond the basics of HollowScript: model choices with enums and let the checker prove every case is handled, take data apart with patterns, count with maps and sets, process text, write generic code, read and build JSON and dates, then learn how capabilities and resource limits keep every program safe. Every example runs on the real HollowScript runtime in your browser.

Recommended first: HollowScript: Working with Data. This course builds on it, but you can open it now.

Free to browse. You sign in at the first lesson so your progress is saved.

Free includes 3 learning hours each week, across all courses. If you use them up, running code pauses until Monday at 00:00 UK time; you can still read lessons and edit your code. Longer courses can be spread over several weeks. How weekly limits work.

About this course

HollowScript 0.1.2 preview in WebAssembly

The real HollowScript runtime, a preview release whose details may change, checks and runs your code in the browser. Varnook supplies print, clock and random to every lesson and refuses any other capability a program asks for.

Maintained by Soulstack

Course overview reviewed
Exercise checks verified

Overview review covers the course summary, stated outcomes and final exercise example. Automated verification ran all 25 reference solutions against their checks and confirmed that starter code does not already pass. This is internal verification.

How exercise checks work

What you will be able to do

  • Model a fixed set of choices with enums and let the checker prove every case is handled
  • Take records, lists and optional fields apart with patterns and destructuring
  • Count, group and compare data with maps and sets, and clean and parse text safely
  • Write generic functions, build and read JSON, and work with dates and timestamps
  • Explain what a program can reach from its uses line and stay inside the run limits

Put it into practice

What you will make

Sharing takings safely

Share a bill without ever dividing by zero, using a Result instead of a fault, and add up 5,000 ticket numbers with a loop that stays inside the call depth limit.

Output from the completed course exercise, using its supplied practice data. From Limits and faults.

Each pays £5.62
Cannot share: nobody to share with
Checksum: 12502500

Syllabus

7 modules and 25 lessons. Each lesson is a short read followed by one exercise with checks.

Module 1

Enums and exhaustive match

Describe a fixed set of choices as an enum, carry values with each choice and let the checker prove that every case is handled.4 lessons, about 52 min
  1. EnumsGive a fixed list of choices a type of its own, then describe each choice with a match.12 min
  2. Variants that carry valuesAttach values to a variant and read them back in the arms of a match.14 min
  3. Why the checker makes you cover every caseAdd a variant and let the checker find every match that needs a new arm.12 min
  4. Enums as stagesWrite one function that says what comes next, then walk a value through its stages with a loop.14 min
Module 2

Records and patterns

Understand records by shape, take lists and records apart in one line and handle fields that may be absent.3 lessons, about 44 min
  1. Records with the same shape are the same typeSee that a record type is a shape, not a label, and why a record with an extra field is refused.12 min
  2. Taking values apartName the parts of a list or a record in one line, in declarations, loops and match arms.12 min
  3. Optional fields inside recordsHandle a record whose field may hold another record or nothing, and match on the shape of a record.20 min
Module 3

Maps and sets

Update maps without changing them, count with a tally, and compare groups with sets.3 lessons, about 38 min
  1. Updating mapsBuild a new map from an old one, look keys up safely and know what merge does with shared keys.14 min
  2. TalliesCount how often each value appears by growing a map that starts empty.12 min
  3. SetsRemove duplicates, test membership and combine groups with a set.12 min
Module 4

Text processing

Split, search, tidy and format text, then turn messy lines into checked data.4 lessons, about 52 min
  1. Splitting and joining textCut a string at a separator, tidy each piece and join the pieces back together.12 min
  2. Searching textTest, find and cut parts of a string, and walk through text one line at a time.14 min
  3. Columns and moneyLine text up in columns with padding, and turn whole pence into pounds for display.12 min
  4. Reading a data fileTurn lines of text into checked numbers, count the lines that fail and never let bad input stop the program.14 min
Module 5

Generics and function values

Write one function for many types and treat functions as values you can store, pass and combine.3 lessons, about 42 min
  1. One function for many typesWrite a function with a type parameter so it works for lists of text, numbers or anything else.14 min
  2. Generic records and enumsDeclare records and enums with type parameters, and see that Result is an enum built the same way.14 min
  3. Functions as valuesStore functions in constants, pass them as arguments, return them, and join two into one.14 min
Module 6

JSON and time

Build and read JSON, and work with calendar dates and timestamps using plain integers.4 lessons, about 1 hour
  1. Building JSONTurn records and lists into a JSON value and write it out as text.12 min
  2. Reading JSONParse JSON text, pull fields out safely and report a parse error with its position.22 min
  3. Calendar datesParse a date, add days with ordinary arithmetic, find the weekday and format the answer.14 min
  4. Times and offsetsParse timestamps that carry an offset, measure the time between them and format the result.14 min
Module 7

Capabilities and limits

See what a program may reach, keep time and chance outside your logic, and meet the limits that stop a runaway run.4 lessons, about 56 min
  1. What a program may doSee how uses and effect make a program's reach visible, and why a program can only do what it declares and what the host grants.16 min
  2. Reading the clockDeclare the clock capability, read the time with effect, and keep the date logic in a function that is given the date.14 min
  3. Random numbersDraw random whole numbers and decimals, and test what must be true of every outcome instead of one lucky value.12 min
  4. Limits and faultsTell a failure you plan for from a fault that stops the program, and learn what each limit looks like when a run reaches it.14 min

Before you start

Some experience from HollowScript: Working with Data is recommended. Times are estimates; practise at your own pace. Every exercise has checks against its brief.

Read how checks, hints and saved work behave. If something is unclear, report a problem with this course and include the lesson link.