Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queen attack #103

Merged
merged 2 commits into from
Sep 21, 2024
Merged

Add queen attack #103

merged 2 commits into from
Sep 21, 2024

Conversation

ageron
Copy link
Contributor

@ageron ageron commented Sep 21, 2024

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 and column 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 and column functions. Instead, the exercise asks the student to write rank and file functions. This also has the additional benefit of reducing the risk of name clashes in the code (in my first implementation, I had a row and column function, and it was a bit painful because several variables had to be named r or c to avoid clashes).

Copy link
Contributor

@isaacvando isaacvando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! This is a really nice way to use opaque types 😃

@ageron ageron merged commit e83f2f6 into exercism:main Sep 21, 2024
4 checks passed
@ageron ageron deleted the add-queen-attack branch September 21, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants