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

Ch13 - clarify exercise to "simplify the result of 'quickCheckPure'" #306

Closed
shaunplee opened this issue Feb 23, 2021 · 3 comments · Fixed by #307
Closed

Ch13 - clarify exercise to "simplify the result of 'quickCheckPure'" #306

shaunplee opened this issue Feb 23, 2021 · 3 comments · Fixed by #307

Comments

@shaunplee
Copy link

shaunplee commented Feb 23, 2021

Chapter 13 has the following exercise, which was added in commit 46d5d2b:

  1. (Medium) Use the all function to simplify the result of the quickCheckPure function - your function should return true if every test passes, and false otherwise. Try using the First monoid, defined in monoids with the foldMap function to preserve the first error in case of failure.

I am having trouble understanding this exercise. The first sentence makes it sound like the exercise is to write a function of type List Result -> Boolean using the all function.

However, it is unclear how to make this work with the second sentence, which asks that we try to "preserve the first error in case of failure" because I don't see how I can encode the first error in a Boolean.

Is the exercise asking the reader to write two functions, one with type List Result -> Boolean and another with type List Result -> First String?

Also, I can't seem to find a monoids package that includes a First newtype. (There seems to have been a monoid package that is now deprecated due to being merged into prelude.) Searching pursuit for "First," it seems like the First newtype from Data.Maybe.First is the monoid most similar to the one called for. If that's the case, then I can update the text to match.

@shaunplee shaunplee changed the title Ch13 - 'quickCheckPure' exercise Ch13 - questions about the exercise to simplify the result of 'quickCheckPure' Feb 23, 2021
@shaunplee shaunplee changed the title Ch13 - questions about the exercise to simplify the result of 'quickCheckPure' Ch13 - clarify exercise to "simplify the result of 'quickCheckPure'" Feb 23, 2021
@milesfrain
Copy link
Member

milesfrain commented Feb 23, 2021

All good points.
FYI, fixed a backtick / single-quote typo in your original post for readability.

I went into skim mode by the end of Ch13, so didn't get around to attempting that exercise, but I think a squashResults :: List Result -> Result is in the spirit of what it wants readers to do.

Doesn't look like foldMap will work with Data.Semigroup.First or Result, since there's no mempty/Monoid for those.
You could use Data.Maybe.First. There might be some even nicer ways to tackle this.

Also, it would be great if we could setup some exercise framework for this chapter. I was kinda stumped on what to do with this, since it's inverted where we're finally asking the readers to write the tests.

@milesfrain
Copy link
Member

Also interesting that all-support for Result was proposed at one point, but doesn't follow the laws. purescript/purescript-quickcheck#101

@hdgarrood
Copy link

The Semigroup and Monoid instances there are fine, it was just the HeytingAlgebra instance which was problematic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants