Skip to content

Scala Practice

Optional language. Scala is not one of the languages this curriculum targets, so these exercises have no reference implementations yet and are excluded from ol verify build and from CI. They are kept because the exercises are worth doing, and every ol command works on them by name.

Toolchain: brew install scala-cli. On a chezmoi-managed machine it comes from the install_alt_langs flag, which is off by default.

scala-cli runs a bare directory of sources and manages its own JVM, so no build definition is needed.

Master functional programming, the type system, and pattern matching on the JVM.

ConceptDetails
Memory ModelJVM GC, value classes, case classes (immutable by default)
Type SystemStrong static, higher-kinded types, variance, path-dependent types
Error HandlingOption, Either, Try, Future recovery, no checked exceptions
ConcurrencyFuture/Promise, Akka actors, cats-effect IO, ZIO
Buildsbt, scala-cli, Mill
StandardScala 3 (Dotty)
  • Case classes for immutable data
  • Pattern matching with exhaustiveness checking
  • For-comprehensions for monadic composition
  • Implicits / given instances (Scala 3) for type-class derivation
  • Sealed traits for algebraic data types
  • Extension methods (Scala 3) over implicit classes
  • Opaque types for zero-cost newtype wrappers
Terminal window
practice/bin/ol list build scala # which of these have references yet
practice/bin/ol start build scala 01 # clone it stubbed into .scratchpad/
practice/bin/ol check build scala 01 # run it; exit code is the verdict
practice/bin/ol diff build scala 01 # your attempt against the reference

Exercises are ordered by concept, not by difficulty, so pick by the stars rather than by the number. An exercise listed below with no reference yet is a row in this table and nothing more; see the practice path for how the harness works.

#ExerciseConceptsDifficulty
01Immutable red-black treeCase classes, pattern matching, recursion⭐⭐⭐
02Monad implementationHigher-kinded types, flatMap, for-comprehension⭐⭐⭐⭐
03Actor system (simplified)Message passing, mailboxes, supervision⭐⭐⭐⭐
04Type-safe builder (phantom types)Phantom types, type-level state machine⭐⭐⭐⭐
05Streaming CSV parserIterator, lazy evaluation, fs2-style⭐⭐⭐
06JSON codec (automatic derivation)Given instances, Mirror, compile-time derivation⭐⭐⭐⭐⭐
07Parallel collection processorFuture, ExecutionContext, Par⭐⭐⭐
08Free monad interpreterGADTs, natural transformations, Church encoding⭐⭐⭐⭐⭐
09Property-based test frameworkGenerators, shrinking, given Arbitrary⭐⭐⭐⭐
10Effect system (mini-ZIO)Trampolining, fibers, error channels⭐⭐⭐⭐⭐