-
-
Notifications
You must be signed in to change notification settings - Fork 112
Add new practice exercise split-second-stopwatch
#749
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
base: main
Are you sure you want to change the base?
Conversation
, Ok (PreviousLaps [ "01:23:45", "04:01:40" ]) | ||
, Ok (CurrentLap "08:43:05") | ||
, Ok (Total "14:08:30") | ||
, Ok (PreviousLaps [ "01:23:45", "04:01:40", "08:43:05" ]) |
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.
The Output
type introduced on top is only used for this exercise, it's the only one where we need to assert the values of different types. It's a little verbose, but it's the best I could come up with.
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.
This is going to make any test failures hard to read. Not sure what the other solutions are, but maybe asserting on all the fields all the time, instead of picking out one for each assertion?
|
||
type Stopwatch | ||
= Stopwatch | ||
{ state_ : State |
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.
what are the underscores for?
|
||
|
||
start : Stopwatch -> Result String Stopwatch | ||
start (Stopwatch ({ state_ } as stopwatch)) = |
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.
Maybe we could use a finite state machine here, instead of using Result (and in the other places)?
, Ok (PreviousLaps [ "01:23:45", "04:01:40" ]) | ||
, Ok (CurrentLap "08:43:05") | ||
, Ok (Total "14:08:30") | ||
, Ok (PreviousLaps [ "01:23:45", "04:01:40", "08:43:05" ]) |
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.
This is going to make any test failures hard to read. Not sure what the other solutions are, but maybe asserting on all the fields all the time, instead of picking out one for each assertion?
This is a brand new one fresh from the problem specs.
Originally, I thought that would be an exercise about time, but really it's much more suited to be our first practice exercise about
opaque-types
.In reality,
Stopwatch
can be implemented as atype alias
, but I opted not to do that in the example solution to push students to use proper opaque types. Of course, we can't stop them from using type aliases, but we could add an analyzer check with some appropriate message. What do you think?