Skip to content

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

Merged
merged 3 commits into from
Jun 13, 2016
Merged

TypeCheckingExercises #7

merged 3 commits into from
Jun 13, 2016

Conversation

oranda
Copy link
Contributor

@oranda oranda commented Jun 12, 2016

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 @bvenners assertTypeError, 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).

@raulraja
Copy link
Member

@oranda Reviewing your PR. A Nat exercise would be awesome!

@raulraja
Copy link
Member

raulraja commented Jun 13, 2016

@oranda The exercise looks great! I'm gonna merge this in.
@dialelo @rafaparadela Can you make sure once master on site is stable with the Contributors changes a new snapshot of the shapeless exercises including @oranda contribution makes it in?

Also this is a great example to test out our new display of exercises contributors.
@oranda Thanks again for your contribution and hoping to have many more like this! Cheers! 🍻

@raulraja raulraja merged commit 3077e62 into scala-exercises:master Jun 13, 2016
@oranda
Copy link
Contributor Author

oranda commented Jun 13, 2016

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.

@milessabin
Copy link

I think I must be missing something wrt assertTypeError. Whether this will assert or not at run time is known at compile time, so what is the motivation for deferring the report rather than delivering it immediately?

@raulraja
Copy link
Member

@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

@milessabin
Copy link

@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?

@milessabin
Copy link

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.

@raulraja
Copy link
Member

We encapsulate all evaluation in a cats.Ior capturing in the fly compilation errors and providing the compile time error information right back at the user in the browser below the exercise : https://github.com/scala-exercises/site/blob/5c6f4150415b86d8b7cc81648e814470c3e91e1e/runtime/src/main/scala/com/fortysevendeg/exercises/MethodEval.scala#L92.

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 Boolean.

https://github.com/scala-exercises/exercises-shapeless/blob/master/src/main/scala/shapeless/TypeCheckingExercises.scala#L32

@raulraja
Copy link
Member

raulraja commented Jun 13, 2016

So basically the exercise is limited to show the user what illTyped is for and allowing them to decide wether two expressions would compile successfully or not.
Also needless to say that if you want push access to this module just let me know since I expect folks to contribute a ton more useful exercises. I basically went over the Shapeless Feature list and started converting them but they can be definitely improved and extended for the greater good :).

@oranda
Copy link
Contributor Author

oranda commented Jun 13, 2016

@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.

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.

3 participants