-
-
Notifications
You must be signed in to change notification settings - Fork 195
If Haskell were to have two-fer and it MUST immediately follow hello-world, what would it look like? #813
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
Comments
Commentary: I feel a vague unease with suggesting either a sentinel value or a separate Note that I similarly advocated for the removal of So I always thought that we would do this exercise with Maybe. But then I thought that perhaps Maybe is too much for the second exercise. This is wild speculation and worth what you pay for it. It is difficult for me to accurately put myself in the shoes of a learner again. In #475 (comment) I justified this with the observation that Learn You A Haskell waited until Chapter 7 out of 14 to introduce Maybe. So this is why I currently think I would stand by my recommendation. The possible avenues to convince me otherwise are either:
Can we learn anything from another track that had a similar discussion? Rust track also added two-fer as the exercise immediately following hello-world in exercism/rust#520 , where we chose the sentinel value choice. While we acknowledged that using the sentinel value was unusual in a situation where Option would do, we also thought it was too early to introduce Option. The exercise was subsequently removed after discussion in exercism/rust#552 ; we still agreed that it was too early to introduce Option and we didn't like having a sentinel value. If an approach such as sentinel value is chosen despite it being unusual, I highly suggest including some explanation (in the tests? in the README?) acknowledging that it is unusual and that a later exercise will teach a more usual way of expressing the absence of a value. |
So long as it is a recommendation, we are still free to choose that which most benefits the track. There is a difference between observing that two-fer works excellently as a 2nd exercise on a variety of tracks, and concluding that it will work best as a 2nd exercise on all tracks.
of what?
So I think we should stick to Our current To generalize my statement: In the middle of the track (where a |
If this actually is true, then we can simply revert the changes made to
|
Since @b-mehta expressed interest in writing an analyser, I would encourage @petertseng's option 1:
because this is the idiomatic way to write such a function.
For the purpose of writing an analyser we could:
What would be the implications of writing an analyser for leap rather than two-fer? It would make sense to write an analyser for an early exercise so we get a lot of feedback. If none of the current early exercises are good candidates, we can add a new one. |
Based on this discussion so far, it currently seems that I should stand by my recommendation; I continue to recommend that Haskell and the other tracks using optional values should not use two-fer as their second core exercise. I will not stand in the way if we collectively decide to ignore this recommendation, though there had better be a good reason to ignore it. Ultimately I can't claim to be an authority on curriculum design and I'm not a mentor on any track, so I can't speak to how such decisions affect the mentor and student experiences. As stated in https://github.com/exercism/automated-mentoring-support , the analysers aim to make mentors' lives easier. Under this consideration there is no reason it has to be two-fer. If it doesn't exist (if the decision becomes not to add it), an analyser for it will not make lives easier. |
The question I wanted to discuss (what would two-fer look like) has been answered. Any desired actions should have their own issue. |
There is a possibility that two-fer (https://github.com/exercism/problem-specifications/tree/master/exercises/two-fer) will become recommended for inclusion on all tracks as the exercise immediately following hello-world.
Previously in exercism/problem-specifications#949 (comment) I recommended that Haskell should not do this (and several other languages).
But this was based on a vague feeling that
two-fer
would be too difficult.That was pure speculation on my part only, and we never got any concrete examples to evaluate.
I'd like to actually have some concrete examples, so that I can evaluate whether I should continue to stand by the recommendation or if I should instead countermand it.
I sketch out a few examples of some ways of rendering
two-fer
in Haskell.For each example, I show what a test for name given and name not given would look like, followed by one or more possible implementations.
Option 1: Maybe
Signature
Tests
Possible implementations
With explicit casing:
Some unfortunate repetition there. Repetition can be reduced with something like:
Ah, but in fact this
Just x -> x; Nothing -> default
pattern is calledfromMaybe
, as follows:Note that student may need to look through http://hackage.haskell.org/package/base/docs/Data-Maybe.html to make that last connection.
Option 2: Sentinel value
Supposing that we treat the empty string as a sentinel value:
Signature
Tests
Possible implementations
Probably something analogous to the above w/
Maybe
.I don't think there's anything similar to
fromMaybe
, so it'd be something like:It could be inlined as well.
Option 3: Two different functions
Signature
Tests
Possible implementations
Most implementations of
twoFer
will probably be the same here:Two main possibilities for how someone might implement
twoFerDefault
would be:With some repetition:
Making it clear that the default is just a specialisation of the general case:
Option 4: Variadic function (like printf)
I am not prepared to provide an example for this, but I suspect from http://okmij.org/ftp/Haskell/polyvariadic.html#polyvar-fn that it would be too much for a position immediately following hello-world.
Option 5: Your Option Here
The above list may not be exhaustive; the floor is open for other ways of expressing this exercise in the language.
Commentary
My own commentary will come in a comment after this so that the options presented are clearly separate from the commentary.
The text was updated successfully, but these errors were encountered: