Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 657eb5c

Browse files
authored
Update exercise instructions (#93)
1 parent 08149a0 commit 657eb5c

File tree

2 files changed

+27
-30
lines changed
  • exercises

2 files changed

+27
-30
lines changed

exercises/exercise_010_opaque_type_aliases/README.md

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ any runtime overhead. The aim is to provide additional type-safety at
88
compile-time but then be stripped away at runtime. It is a powerful new feature
99
of Scala 3 for supporting Information Hiding.
1010

11-
Opaque Type Aliases differ from plain Scala 2 Type Aliases in that the later
12-
just provide a new name for a type but wherever this new name is used, the
11+
Opaque Type Aliases differ from plain Scala 2 Type Aliases in that the latter
12+
just provides a new name for a type but wherever this new name is used, the
1313
call-site still knows the details of the original type being aliased. With
1414
Opaque Type Aliases, the original type being aliased is hidden (or is opaque) at
1515
the call-site.
@@ -31,14 +31,13 @@ type CellUpdates = Vector[(Int, Set[Int])]
3131
```
3232

3333
To keep things manageable we will only focus on one of these type aliases for
34-
this exercise. Specifically we will convert the last of these type aliases,
35-
`ReductionSet` into an Opaque Type Alias.
34+
this exercise. Specifically we will convert the `ReductionSet` type aliases
35+
into an Opaque Type Alias.
3636

37-
- Start by moving the type alias to a new source file, `ReductionSet`.
37+
- Start by moving the type alias to a new source file, `ReductionSet.scala`.
3838

39-
- Now add the keyword `opaque` in front of the type alias
40-
declaration and recompile. Do you expect this to compile successfully? If not,
41-
why?
39+
- Now add the keyword `opaque` in front of the type alias declaration and
40+
recompile. Do you expect this to compile successfully? If not, why?
4241

4342
- So it seems we need to tackle quite a few compilation errors... Let's get
4443
started.
@@ -47,30 +46,30 @@ this exercise. Specifically we will convert the last of these type aliases,
4746
> `value {name} is not a member of ...` before tackling the other types
4847
> of error like `Found: ... Required: ...`
4948
50-
- The first errors are in the source file `ReductionRules`. As this file contains
51-
two extension methods on `ReductionSet`, moving these to `ReductionSet` will
52-
resolve these errors.
49+
- The first errors are in the source file `ReductionRules.scala`. As this file
50+
contains two extension methods on `ReductionSet`, moving these to `ReductionSet`
51+
will resolve these errors.
5352

54-
- Next up is an error linked to value `InitialDetailState`. It's an
55-
`InitialDetailState` which is a `ReductionSet`. Again, move it to the
56-
`ReductionSet` source file. You may have to annotate its type.
53+
- Next up is an error linked to value `InitialDetailState`. It's a `ReductionSet`,
54+
so again, move it to the `ReductionSet.scala` source file. You may have to
55+
annotate its type.
5756

58-
- Recompile and look at the first few error in source file `SudokuDetailProcessor`.
57+
- Recompile and look at the first few error in source file `SudokuDetailProcessor.scala`.
5958
These are linked to methods `mergeState`, `stateChanges`, and `isFullyReduced`.
6059
As these 3 methods all take a `ReductionSet` as argument, it makes sense to
6160
convert them to extension methods on `ReductionSet`. Do so, and adapt the
62-
call sites to take the change into account. Note that you may have to change
61+
call sites to take this change into account. Note that you may have to change
6362
the visibility of the methods.
6463

65-
- Recompile and notice the errors in `SudokuIO`. The relevant code is doing some
64+
- Recompile and notice the errors in `SudokuIO.scala`. The relevant code is doing some
6665
kind of pretty print of a `Vector[ReductionSet]` (which is a `Sudoku`; see the
6766
type alias in `TopLevelDefinitions`). Move the method `SudokuRowPrinter` to
6867
`ReductionSet` and convert it to an extension method (name it `printSudokuRow`).
6968
Move the private `sudokuCellRepresentation` helper method along with it. Make
7069
the necessary changes at the call site.
7170

7271
- Recompile. Notice the extension methods on `SudokuField` that are now in error.
73-
Move these to `ReductionSet` and recompile. Methods `randomSwapAround` and
72+
Move these to `ReductionSet.scala` and recompile. Methods `randomSwapAround` and
7473
`toRowUpdates` show errors.
7574

7675
- The core issue with method `randomSwapAround` is the mapping on a `ReductionSet`.
@@ -79,9 +78,10 @@ this exercise. Specifically we will convert the last of these type aliases,
7978
Make the necessary changes to `randomSwapAround` to make it compile.
8079

8180
- The core issue with method `toRowUpdates` is invoking `zipWithIndex` on `ReductionSet`.
82-
Add a private extension method `zipWithIndex` on `ReductionSet`.
81+
Add a _private_ extension method `zipWithIndex` on `ReductionSet`. What should its
82+
return type be?
8383

84-
- We've almost eliminated all complilation errors. The last error can be corrected
84+
- We've almost eliminated all compilation errors. The last error can be corrected
8585
by adding an apply method in a `ReductionSet` companion object that allows
8686
one to create a `ReductionSet` from a `Vector[CellContent]`.
8787

@@ -99,13 +99,9 @@ It does raise some questions:
9999
- Was it worth the effort?
100100
- What have we gained, if anything?
101101
- Are there alternatives to this approach?
102-
- What are the gotchas
103-
104-
There are many more potential type aliases to which we could apply the same
105-
procedure. One that sticks out is the `Sudoku` type alias
106-
(`type Sudoku = Vector[ReductionSet`).
107-
108-
109-
102+
- What are the gotchas
110103

104+
There are more type aliases in the source code that potentially could be converted to
105+
opaque versions. One that sticks out is the `Sudoku` type alias
106+
(`type Sudoku = Vector[ReductionSet`). You may want to take a stab at converting it...
111107

exercises/exercise_011_multiversal_equality/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ error.
2828
## Steps
2929

3030
- Enable multiversal equality at the project level by adding `-language:strictEquality`
31-
to the Scalaa compiler options in `project/Build.scala`
31+
to the Scala compiler options in `project/Build.scala`
3232

3333
- Use the course notes on Multiversal Equality and your experience from the
3434
exercise on `given`s to make the code compile with the flag
3535
`-language:strictEquality` enabled
3636
- Hint: The simplest solution will probably involve using `CanEqual.derived`
3737

3838
- Run the provided tests by executing the `test` command from the `sbt` prompt
39-
and verify that all tests pass
39+
and verify that all tests pass
40+

0 commit comments

Comments
 (0)