-
Notifications
You must be signed in to change notification settings - Fork 26
TypeCheckingExercises #7
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
Conversation
@oranda Reviewing your PR. A |
@oranda The exercise looks great! I'm gonna merge this in. Also this is a great example to test out our new display of exercises contributors. |
Thanks @raulraja, hope the ideas will be useful. I will only get to look at scala-exercises on weekends unfortunately, because I have a lot of work during the week. |
I think I must be missing something wrt |
@milessabin We evaluate the exercises at runtime when the user provides an answer of what he expects the result of the code to be. that answer is evaluated with the rest of the exercise method body and compiled in the fly. Ultimately we will also let them extract the exercise content and play with it in JS fiddle style fashion right on their browser, which means they may be able to change the content around to play with it. I´m not sure if this answers your questions, I´d be happy to expand on any of those areas. thanks |
@raulraja suppose the user provided an answer which had some other compile time error (eg. missing closing parenthesis, or use of an undefined val or method or something like that) ... when would you report those sorts of error? |
Just to be clear, I'm trying to get a handle on whether this is something I think ought to be added to shapeless. So far I'm still not getting the motivation. |
We encapsulate all evaluation in a In this case anything that the user would provide that can't be coerced to a Boolean will be reported as such since the exercise inout args types are |
So basically the exercise is limited to show the user what |
@milessabin I hope @raulraja has answered your question to your satisfaction. If you can see a better way to write this exercise, you're welcome to suggest it or modify the exercise directly. |
This is an example of exercises that address the issue in scala-exercises/scala-exercises#393.
The feature being demonstrated from Shapeless is
illTyped
. This causes an expression to fail at compile-time. The first part of text in the exercise is taken from @milessabin's classic documentation as with the rest of the exercises.The tests use ScalaTest's
assertTypeError
which doesn't fail at compile-time but throws an exception, which I then convert to a Boolean. I think this technique could be useful for compile-time checking throughout the exercises, e.g. in the CSV parsing. However, you might want to refine it. For instance, you could write your own macro, similar to @bvennersassertTypeError
, but returning a Boolean. Also feel free to change the text of this exercise in any way.By the way, it would also be nice to have an exercise for Shapeless Nat (natural numbers).