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

Concept Algebraic Data Types with exercise #1110

Merged
merged 2 commits into from
Oct 7, 2022
Merged

Conversation

pwadsworth
Copy link
Contributor

First stab at introducing ADTs and the associated exercise (Valentines Day) to get the conversation and edits started.

@MatthijsBlom
Copy link
Contributor

MatthijsBlom commented Sep 20, 2022

This formulation of Valentine's Day requires the student to use general (i.e. not literal-specific) pattern matching, which has not yet been introduced.

I expected Valentine's Day to be used for Pattern Matching. Either way, an extra exercise needs be found for the Concept not paired with Valentine's Day.

@pwadsworth
Copy link
Contributor Author

pwadsworth commented Sep 21, 2022

@MatthijsBlom
You are right. I forgot about the discussion under #1103 and went with the original conversation on slack from 27 Aug.
We could keep these Valentine's Day (VD) files for PM2, and develop a different exercise for ADTs, but after looking for alternatives, I think VD is better suited for ADTs than the alternatives. It is a straight forward application of the types and the jump from PM1 to this is minimal. Several other tracks use it for ADT and then go on to more complex exercises in PM (proper).

What do you think of Ticket Please for PM2? it seems better suited for a more in-depth look a PM as it makes use of de-structuring, record updates, and requires previous exposure to tuples, records and ADTs.

@pwadsworth

This comment was marked as resolved.

@pwadsworth

This comment was marked as resolved.

@petertseng
Copy link
Member

Well, ALLOWED-TO-NOT-COMPILE implies that the stub doesn't compile. But, this current stub does compile. Therefore, it's forbidden to add ALLOWED-TO-NOT-COMPILE. If the stub cannot be tested, you're supposed to use DONT-TEST-STUB instead.

@pwadsworth
Copy link
Contributor Author

@petertseng thanks, that took care of it.
Do you know if there is any documentation I can read about the different flags available?

@petertseng
Copy link
Member

https://github.com/exercism/haskell#stub-solution is the documentation for DONT-TEST-STUB. I find no documentation for STUB-ALLOWED-TO-NOT-COMPILE. I wouldn't really like to advertise those features. Every instance of those means more manual work that has to be done to make sure the stubs are good, and more manual work means the track is harder to maintain.

@pwadsworth
Copy link
Contributor Author

pwadsworth commented Sep 27, 2022

I must admit it is quite embarrassing the problem, and its solution, can be found clearly spelled out in a file I updated just a couple days ago... 😊

exercises/concept/valentines-day/.meta/config.json Outdated Show resolved Hide resolved
exercises/concept/valentines-day/src/ValentinesDay.hs Outdated Show resolved Hide resolved
exercises/concept/valentines-day/src/ValentinesDay.hs Outdated Show resolved Hide resolved

rateActivity :: Activity -> Approval
rateActivity activity =
case activity of
Copy link
Member

Choose a reason for hiding this comment

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

This implementation uses case, which I don't think is being taught in the prerequisites, correct? If so, we'll need to add another exercise to teach that or rewrite this to use the pattern matching functionality that was already introduced.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

case is introduced in this concept (last paragraph of introduction.md)

@pwadsworth
Copy link
Contributor Author

All previous comments addressed. Just pending decision on introducing case expressions together with ADTs. IMO they are complementary concepts.

exercises/concept/valentines-day/.docs/hints.md Outdated Show resolved Hide resolved
exercises/concept/valentines-day/.docs/hints.md Outdated Show resolved Hide resolved
exercises/concept/valentines-day/.docs/hints.md Outdated Show resolved Hide resolved
exercises/concept/valentines-day/.docs/hints.md Outdated Show resolved Hide resolved
Comment on lines +8 to +10
case rateActivity Chill of
No -> True
_ -> False
Copy link
Member

Choose a reason for hiding this comment

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

Surprising. It correctly rejects incorrect implementations, but has the disadvantage of not showing the correct vs incorrect result. I wish there were a way to do that.

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

Great work!

@ErikSchierboom
Copy link
Member

@petertseng Feel free to merge as you feel fit.

Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

There are no tests for Walk. Shouldn't there be some? I added them.

- Chill out: no.
- Watch a movie: yes if it is a romantic movie; otherwise, no.
- Go to a restaurant: yes if the cuisine is Korean, maybe if it is Turkish.
- Take a walk: yes if the walk is less than three kilometers; maybe if it is between three and five kilometers (inclusive); otherwise, no.
Copy link
Member

Choose a reason for hiding this comment

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

I added the (inclusive) here. Even though I think it was fairly obvious it's inclusive (if it wasn't, the only value that gets a Maybe would have been 4, the answer for 3 would have been undefined), I wanted to be explicit anyway.

Comment on lines +39 to +54
it "walk 2 kilometers rated yes" $
case rateActivity (Walk 2) of
Yes -> True
_ -> False
it "walk 3 kilometers rated maybe" $
case rateActivity (Walk 3) of
Maybe -> True
_ -> False
it "walk 5 kilometers rated maybe" $
case rateActivity (Walk 5) of
Maybe -> True
_ -> False
it "walk 6 kilometers rated no" $
case rateActivity (Walk 6) of
No -> True
_ -> False
Copy link
Member

Choose a reason for hiding this comment

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

there were not any tests for walk, before I added them.

@petertseng petertseng merged commit 7e54949 into exercism:main Oct 7, 2022
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.

4 participants