Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think this exercise is a good opportunity to use an opaque type.
Square := { row : U8, column : U8 }
is an opaque type that represents a chessboard square, and it is guaranteed to be valid (i.e.,row
andcolumn
are both between 0 and 7). This illustrates the fact that opaque types can enforce constraints.I also wanted to show that the implementation details could be hidden from the user, so I didn't want to simply provide
row
andcolumn
functions. Instead, the exercise asks the student to writerank
andfile
functions. This also has the additional benefit of reducing the risk of name clashes in the code (in my first implementation, I had arow
andcolumn
function, and it was a bit painful because several variables had to be namedr
orc
to avoid clashes).