Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jiegillet
Copy link
Contributor

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 a type 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?

, 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" ])
Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link
Contributor

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)) =
Copy link
Contributor

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" ])
Copy link
Contributor

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?

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.

2 participants