haskell
haskell copied to clipboard
Implement Concept Exercise for pattern matching: Guessing Game
We'd like to introduce pattern matching, and we think Guessing Game is a suitable story for this: https://exercism.org/docs/building/tracks/stories/pattern-matching-number-guessing-game
Both Elixir and F# have implemented this exercise, so it's worth taking a look at those implementations to see if there's anything there that is useful to us here.
- F#: https://github.com/exercism/fsharp/tree/main/exercises/concept/guessing-game
- Elixir: https://github.com/exercism/elixir/tree/main/exercises/concept/guessing-game
Here's a sample code snippet courtesy of @MatthijsBlom that might be suitable as a starting point.
reply 41 = SoClose
reply 42 = Correct
reply 43 = SoClose
reply n = if n < 42 then TooLow else TooHigh
We will introduce pattern matching in more depth over time, so in this first exercise we'd like to explain just enough to let students complete the exercise. We should also explain enough about types so that SoClose
, Correct
and friends aren't mystifying.
To start out, let's just get a sample solution, test suite, and stub together so that we can discuss (both in terms of Haskell and in terms of Exercism Concept Exercises).
After that in follow-on PRs we can develop the instructions (which can then be tested and discussed), and then finally the introduction.
The concept will also need to be worked on. We can do that at the same time as the introduction, or we can start on it earlier. I'm not opening an issue for it yet, but if you want to work on that drop a note in the discussion below so that we know it's being worked on.
Note that we're still working out how to best work with contributors on these concept exercises. If you have questions, please holler! We'll do our best to help figure out how to proceed.
Starting step 1 (exemplar, tests and stub). I will put it in a draft PR today.
If the solution expects use of custom types we should make that concept first.
An alternative is to use case
statements to introduce pattern matching and return a String like the F# track does.
Preference?
@kytrinyx step 1 draft PR is ready. Do you want to create a separate branch to send it to, or should I use main?
Ok, I got inpatient and did the instructions and introduction before any feedback ¯\(ツ)/¯
Also changed my mind about using case
statements and refactored the exemplar to use constant patterns and guards. This aligns closer with how it was done for the F# track.
Do you want to create a separate branch to send it to, or should I use main?
You can always submit the pull requests against main.
Ok, I got inpatient and did the instructions and introduction before any feedback ¯(ツ)/¯ Also changed my mind about using case statements and refactored the exemplar to use constant patterns and guards. This > aligns closer with how it was done for the F# track.
Let's discuss this a bit further on Slack