The Scala track has 102 practice exercises and no learning path: status.concept_exercises is false, there is no concepts/ directory, and the only concept exercise is a wip Lasagna (exercises/concept/basics). Now that the practice exercises are on Scala 3 and mostly in sync with problem-specifications (exercism/scala#488), I’d like to start on the syllabus (exercism/scala#652).
Before writing any content I’d like feedback on the concept tree below.
Guiding ideas
- Scala 3 only. Indentation syntax,
enum,given/using, extension methods. - Functional core first, classes later. Most students arrive from Java or Python and can already write Scala as “Java without semicolons”. The syllabus should get them to
match, case classes,Optionand collection operations quickly. Classes, traits and mutable state come after that core rather than before it. - Errors are values.
OptionandEitherare taught early; exceptions andTrylate. This matches how the practice exercises on the track already report errors. - No loops branch.
whileandvarare mentioned, not taught through an exercise. Iteration is taught through collection operations, recursion andforcomprehensions. - Reuse existing stories. Every exercise below is an existing Exercism story, mostly taken from the F#, Elixir, Java and C# tracks.
- Not a copy of Java’s tree. Java has 24 active concept exercises; several of its concepts have no place here (
for-loops,switch-statement,ternary-operators,nullability,constructors,method-overloading) and several Scala concepts have no Java counterpart.
Stage 1 — the first six
The docs suggest the design team builds the first five or six concepts before opening up to contributions. These are the ones every later exercise depends on.
| # | Exercise (story) | Concepts | Prerequisites | Taken from |
|---|---|---|---|---|
| 1 | lucians-luscious-lasagna |
basics |
— | exists as wip |
| 2 | annalyns-infiltration |
booleans |
basics |
Java, F# |
| 3 | cars-assemble |
numbers, if-expressions |
booleans |
Java, F# |
| 4 | log-levels |
strings |
basics |
Java, F# |
| 5 | guessing-game |
pattern-matching |
if-expressions, strings |
F# |
| 6 | tisbury-treasure-hunt |
tuples |
pattern-matching, strings |
F# |
Notes:
basics:val,def, type inference,Intarithmetic, comments.stringsincludess"..."interpolation.if-expressions:ifreturns a value, so there is no ternary operator to teach.pattern-matchingat this point ismatchon literals, variable and wildcard patterns, and guards. Destructuring is added by the concepts that introduce something to destructure (tuples, case classes, enums, lists).
Stage 2 — the functional core
| # | Exercise (story) | Concepts | Prerequisites | Taken from |
|---|---|---|---|---|
| 7 | bandwagoner |
case-classes |
pattern-matching, numbers, strings |
F# (records) |
| 8 | valentines-day |
enums |
case-classes |
F# (discriminated-unions) |
| 9 | role-playing-game |
options |
case-classes, tuples |
F# |
| 10 | tracks-on-tracks-on-tracks |
lists |
pattern-matching, strings, booleans |
F# |
| 11 | secret-agent |
higher-order-functions |
numbers, strings |
Kotlin (wip) |
| 12 | bird-watcher |
collection-operations |
lists, higher-order-functions |
Java, F# |
| 13 | pizza-pricing |
recursion |
enums, lists |
F# |
| 14 | password-checker |
either |
options, enums |
F# (results) |
Notes:
enumscovers both simple and parameterised cases, plus exhaustivematch. In other words, algebraic data types the Scala 3 way.sealed traithierarchies are left totraits.optionstakes the place of Java’snullability.lists: the immutableList,::,head/tail, and matching onNil/head :: tail.higher-order-functions: function types, lambdas,_placeholder syntax, returning functions.collection-operations:map,filter,exists,count,sum,take,foldLeft. On Java’s trackbird-watcherteaches arrays and loops; here the same story is solved without either.recursionincludes@tailrec.
I’d propose launching (status.concept_exercises: true) when stages 1 and 2 are done: 14 exercises, 15 concepts. That is close to F#'s live syllabus (17 exercises).
Stage 3 — the rest of everyday Scala
| # | Exercise (story) | Concepts | Prerequisites | Taken from |
|---|---|---|---|---|
| 15 | international-calling-connoisseur |
maps |
options, tuples, collection-operations |
Java, C# |
| 16 | gotta-snatch-em-all |
sets |
lists, collection-operations |
Java, Elixir |
| 17 | boutique-suggestions |
for-comprehensions |
collection-operations, options, tuples |
Elixir (list-comprehensions) |
| 18 | squeaky-clean |
chars |
strings, collection-operations |
Java, F# |
| 19 | jedliks-toy-car |
classes |
numbers, strings, if-expressions |
Java |
| 20 | need-for-speed |
objects |
classes |
Java (constructors) |
| 21 | remote-control-competition |
traits |
classes, lists |
Java (interfaces) |
| 22 | calculator-conundrum |
exceptions |
either, classes |
Java |
Notes:
classesis wherevar, private state and constructor parameters are taught.objects: singleton and companion objects,apply, factory methods.exceptionscoversthrow,try/catchandscala.util.Try, mainly as what you meet when calling Java libraries.
Stage 4 — candidates, in no particular order
extension-methods (log-analysis, C#), generics, given-using, type-classes, opaque-types, union-types, lazy-lists (lucas-numbers, Elixir), ranges (chessboard, Elixir), vectors-and-arrays, partial-functions, default-and-named-arguments (wizards-and-warriors-2), regular-expressions (log-parser), bit-manipulation (secrets), randomness (captains-log), datetime (booking-up-for-beauty, on java.time), futures.
These are a list of ideas rather than a plan. Following the docs’ advice, the tree can grow from here one exercise at a time.
The tree
basics
├── booleans
│ └── numbers, if-expressions
│ └── pattern-matching (also needs strings)
│ ├── tuples
│ ├── case-classes
│ │ ├── enums
│ │ │ ├── recursion (also needs lists)
│ │ │ └── either (also needs options)
│ │ └── options (also needs tuples)
│ └── lists
│ └── collection-operations (also needs higher-order-functions)
│ ├── maps (also needs options, tuples)
│ ├── sets
│ ├── for-comprehensions (also needs options, tuples)
│ └── chars
├── strings
│ └── higher-order-functions (also needs numbers)
└── (via numbers, strings, if-expressions) classes
├── objects
├── traits (also needs lists)
└── exceptions (also needs either)
Practice exercises
Once a concept is live, the practice exercises get practices and prerequisites. A first, rough mapping, to show that the existing exercises cover the tree:
| Concept | Practice exercises that could practise it |
|---|---|
booleans |
leap |
numbers |
space-age, grains, difference-of-squares, darts, armstrong-numbers |
strings |
two-fer, reverse-string, acronym, pig-latin |
pattern-matching |
bob, raindrops, yacht |
case-classes |
clock, complex-numbers, queen-attack |
enums |
allergies, robot-simulator, bowling |
options |
hamming, all-your-base, say, change, phone-number, binary-search |
lists |
sublist, flatten-array, simple-linked-list |
higher-order-functions |
accumulate, strain |
collection-operations |
sum-of-multiples, scrabble-score, high-scores, series, sieve |
recursion |
collatz-conjecture, prime-factors, pascals-triangle, binary-search-tree |
either |
forth, protein-translation (after exercism/scala#947) |
maps |
etl, word-count, nucleotide-count, grade-school |
sets |
pangram, isogram, anagram, custom-set |
for-comprehensions |
pythagorean-triplet, saddle-points, palindrome-products, zebra-puzzle |
classes |
bank-account, robot-name, circular-buffer, linked-list |
Tooling that needs work first
- The test runner emits results version 2. Concept exercises are better served by version 3, which groups tests by task (
task_id). - reference/implementing-a-concept-exercise.md is a TODO stub and needs writing before contributors can help.
- The
wipLasagna lives under the slugbasics. Concept exercises are named after their story, so I’d rename it tolucians-luscious-lasagnawhile it is stillwip.
Questions
- Does the “functional core first, classes later” order look right, or should
classesmove into stage 2? - Is 14 exercises a reasonable point to switch learning mode on, or would you launch earlier or later?
- Any concept you’d add to, or drop from, stages 1–3?
- Is anyone interested in reviewing or writing concept exercises for the track?
The plan is one concept exercise per PR, in the order above, with the concept’s about.md / introduction.md / links.json in the same PR.