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

Ch2 Exercises introduces Pursuit with an empty search #259

Closed
armatures opened this issue Dec 21, 2020 · 8 comments · Fixed by #266
Closed

Ch2 Exercises introduces Pursuit with an empty search #259

armatures opened this issue Dec 21, 2020 · 8 comments · Fixed by #266

Comments

@armatures
Copy link

In the exercises for chapter 2, the user is directed to "search Pursuit to find the module that contains the readFloat function and import that module." The containing module, Global, is deprecated, and Pursuit no longer indexes deprecated modules. The easiest fix would be to change that example to something easy to search for in a package that's not deprecated.

@milesfrain
Copy link
Member

Thanks for catching and reporting this issue.

Looks like Global was deprecated 4 days ago in preparation for our upcoming 0.14 release.

Unfortunately, Pursuit can become out of sync with what's actually available in latest package set (a bit too bleeding edge in this case). That should improve once we get the new registry online. Until then, you can also check this pursuit clone which is pinned to the latest package set.

Anyway, let's go with your suggestion of updating the example.

The replacement for readFloat is fromString, but that's not very beginner-friendly to search for and Maybe is another unfamiliar concept.

I can't think of anything else that's chapter-2-appropriate to search for on pursuit. Let me know if you have any ideas. We can alternatively defer the pursuit exercise until a later chapter.

@armatures
Copy link
Author

I'm not sure how the Global package was brought in, but it's nice to have a function to look up that's already a dependency, so the user doesn't have to learn about adding them. Maybe Global is special somehow in that regard? Grepping global doesn't really bring anything up for me in the project—it's not important except that it would be nice to replace the exercise with something that had that same property. Math is already in scope, so maybe the Pursuit search could be for remainder or something? All the other function names in that package are abbreviated and so not particularly searchable.

It might be silly, but we could do something like isDivisibleBy3. Maybe this problem stumbles into Number vs Int distinctions, though: running remainder 9 3 in psci doesn't work, but remainder 9.0 3.0 is happy.

@milesfrain
Copy link
Member

milesfrain commented Dec 23, 2020

I believe Global was originally featured in this exercise because it's another module to import.

rem from Data.Int might be a good substitute.

What about this for an exercise?

Write a function leftoverCents which takes an Integer and returns what's leftover after dividing by 100. Use the rem function. Search Pursuit for this function to learn about usage and which module to import it from. Note: Your IDE may support auto-importing of this function if you accept the auto-completion suggestion.

Feel free to make a PR for this change. You're welcome to use the above snippet, or whatever else you think would be a good substitute. I'll help out with whatever additional CI fixups might be necessary.

@JordanMartinez
Copy link

Global will be deprecated in v0.14.0, so you should probably use a different module.

@gdennie
Copy link

gdennie commented Feb 8, 2021

The current simple solution to implementing the last exercise, leftoverCents, by searching and importing the remainder function, rem function using Pursuit is presently problematic. The simple solution,

import Data.Int (rem)
...
leftoverCents d = rem (d / 100.0)

...generates the error: Count not match type Number with type Int. I presume the exercise was not intended to throw the reader into a Pursuit of experimentation for suitable definitions.

@milesfrain
Copy link
Member

@gdennie Thanks for the feedback.

Note that rem takes two integer arguments (you are just giving it one argument, but also performing an unnecessary division). I was hoping this would be clear with the examples on pursuit, but perhaps they can be improved. I'd be happy to hear any suggestions you have for making this exercise more straightforward for readers.

Here's what I see as my first pursuit result for rem:

rem :: Int -> Int -> Int

rem 2 3 == 2

For context, here's the exercise:

(Medium) Write a function leftoverCents which takes an Integer and returns what's leftover after dividing by 100. Use the rem function. Search Pursuit for this function to learn about usage and which module to import it from. Note: Your IDE may support auto-importing of this function if you accept the auto-completion suggestion.

@gdennie
Copy link

gdennie commented Feb 8, 2021

Thanks.

I did realized my mistake in bed reflecting. :)

Incidentally, the exercises should be using npx, as in npx spago test, to avoid needing global install. It presents a more robust solution especially in docker containers with non root user, which I've setup.

@milesfrain
Copy link
Member

Incidentally, the exercises should be using npx, as in npx spago test, to avoid needing global install. It presents a more robust solution especially in docker containers with non root user, which I've setup.

I think that's more of a matter of preference. For most folks starting out, global install is the most convenient. And if you're installing via nvm (as recommended in the "getting started" section), you shouldn't need root access.

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.

4 participants