-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add record types concept and associated exercise #369
Conversation
Thanks for this! It's great since I'll need it as a dependency for the exercise I'm making for
Let me know what you think of all this. |
Thanks Matthieu, those changes look good. I should finish the rest of the PR by the weekend I think. |
f3569d4
to
8221658
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ceddlyburge . I've finally had some time to review again your changes. I've rebased this on a newer main
commit to avoid merge conflict with list concept. I was surprised that you didn't go for TV shows for the exercise but I like the bandwagoner theme too! I have some questions and remarks about the exercise, here they are.
Are you using only the record constructors in the examples to not disclose the structure too much, or for example brevity? It is usually preferable to use the curly braces syntax to define them because the constructors are dependent on order, thus potential sources of hard-to-find bugs. So I'm not sure if it is worth trying to have shorter code examples if it gives the wrong habits to students. What do you think?
For the replaceCoach
function, I'd reverse the order of arguments. It's generally good to end arguments with the same type that is transformed since it improves readabily in pipes, so Coach -> Team -> Team
.
Do you think the isSameTeam
task is worth it? Equality in Elm works the same everywhere, and there is no concept of referential equality (except for Html lazy but that's a very particular edge case), and there is only one operator ==
so it's not like they could get it wrong.
I'm wondering if the small paragraph in the introduction is enough.
I feel the exercise is missing a "constructor" function. By that I mean a function that would make the student write the { field = ..., ... }
entirely. I feel like a good function to do that would be to provide the arguments in the wrong order, compared to the auto-generated constructor. Something like this where Stats
and Coach
are reversed, preventing the student to use the Team
constructor.
createTeam : String -> Stats -> Coach -> Team
createTeam name stats coach =
And at the beginning, in the instructions to define the model, we should add "with the following fields, in the following order". Then the first tests should check that the order is respected. And Same for the other type aliases.
test "Coach type alias is correctly defined" <|
\_ ->
Coach "Steve Kerr" True
|> Expect.equal
{ name = "Steve Kerr"
, formerPlayer = True
}
Finally, regarding the rootForTeam
function, if we want to make students use the extensible record syntax, we should add a test with a record that isn't a Team
.
I have been trying to pick the low hanging fruit, and copy exercises from other languages. I didn't come across the TV shows one when I was looking, which track is this on (I looked at quite a few function type tracks, such as F#, Scala, Haskell, Clojure, Rust etc) |
This is a fair point, although I often use the constructors, partly because it communicates the type you are creating. It's true that if you have multiple properties of the same type it would be easy to mix them up though. I'll commit some changes. |
Fair point, I'll commit this change now |
Yep, fair enough, I'll remove this |
Good point, I've done this. |
|
|
I think that is all the feedback for this PR addressed now, can you give it another look? Thanks, Cedd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! one more concept ;)
Add records concept and associated exercise
The configlet linter is still failing, but this has been fixed in main, so will be fixed when this is merged.