-
Notifications
You must be signed in to change notification settings - Fork 195
Ch6 Action exercises - clarify typeclass law reminder #348
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
Ch6 Action exercises - clarify typeclass law reminder #348
Conversation
The original exercise for When tests where added - prior to #338, accepted solutions were narrowed down to a specific implementation (that satisfies the laws). This was probably the time to have changed "Does this instance satisfy the laws listed above?" to "Verify that this instance satisfies the laws listed above.". Satisfying laws has become a criterion of a passing solution. #338 took care of that. For the exercise I think the phrase "Does this instance satisfy the laws listed above?" does just that. It's not an inconsistency. |
I feel like we should only be reminding readers about the typeclass laws in the first exercise (at most). What are your thoughts on the latest version of this PR? Changed the "Verify..." language, since I can image that being interpreted by readers as another step with more code to write, rather than something that's already handled by the tests. |
text/chapter6.md
Outdated
@@ -648,7 +648,7 @@ Another reason to define a superclass relationship is in the case where there is | |||
```haskell | |||
instance actionMultiplyInt :: Action Multiply Int | |||
``` | |||
Verify that this instance satisfies the laws listed above. | |||
_Note_: Your instance must satisfy the type class laws listed above in order to pass the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, just "Remember, your instance must satisfy the laws listed above." will do. Doesn't need to be wrapped in a Note. Passing tests should go without saying.
I agree "Verify" does sound like an extra step.
@@ -659,8 +659,6 @@ Another reason to define a superclass relationship is in the case where there is | |||
``` | |||
_Hint_: Search Pursuit for a helper-function with the signature [`String -> Int -> String`](https://pursuit.purescript.org/search?q=String%20-%3E%20Int%20-%3E%20String). Note that `String` might appear as a more generic type (such as `Monoid`). | |||
|
|||
Does this instance satisfy the laws listed above? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the goal here is to call attention to abiding to typeclass laws. This is one of the weak parts of the language were the type system and the compiler does not help. It's merely a hand-shake contract between authors. So I'm against removing this reminder altogether.
Some alternatives
- "Convince yourself that this instance satisfies the laws listed above."
- "Note that this instance satisfies the laws listed above."
However, I like the original question form in that it naturally stimulates curiosity. It becomes a personal mission to find out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, then why not also include this reminder a third time in the next exercise, and maybe a fourth time in the exercise after that too?
My argument against including the reminder here is that it seems redundant after the reminder in the first exercise.
The latest version of the PR includes all four Remember, ...
lines. I think we should only keep the first one. If you think it would be better to include the first two, we could do that also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think twice is quite enough. For a reader, the first time brings about the idea. The second time hardens it. The third time, well, starts to seem redundant. The fourth time, it's either, this is getting annoying, or, starting to think this must be of supreme importance! hence the repetition.
The theme of this book is "by example". Not everything is explained to the detail. Prior to these exercises, typeclass laws were mentioned only briefly (first time when introducing Functor laws, and second time when mentioning super class relation). Then jumps into implementing a typeclass with laws. So for the first time, definitely stress that laws must be satisfied. The second time, a gentler reminder. Twice should be enough to set the pattern for the subsequent times. If not, the tests will kick in.
So I stand by the use of phrases "Remember, ..." for the first time, and "Does this instance satisfy..." for the second time. And not for subsequent exercises.
Follow-up to #338
This phrasing is also used in the previous exercise. This PR simply makes the phrasing consistent, but I think we should actually eliminate these lines from both exercises.
These lines don't contribute much for the student, since we have tests to verify the student's solution satisfies the laws. Including these lines might even add confusion, since this could seem like an extra step that we're asking. Really, every exercise could include a similar "Verify that your solution meets the exercise requirements", which I think is equally unnecessary here.