-
Notifications
You must be signed in to change notification settings - Fork 382
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
list exercise error #34
Comments
Hi, it’s true that the example doesn’t compile. The idea was more to show various kinds of patterns. |
For someone new to Scala like me this could be a bit confusing. I think this can be refactored to show two lists or remove the last case altogether. |
I agree with @ibrahim-islam that any code should be copy-paste ready to try out and play with it. Maybe you want to make the code compile, @ibrahim-islam? |
Yes and while at it maybe do a PR to make this right for future learners :) |
@ibrahim-islam make a proposal :) Ping me if you like to discuss it :) |
While the example is interesting in that it shows an example of advanced pattern matching, it is problematic in that the pattern used is not of a valid type for the rest of the code. As it is not really relevant to the issue at hand, and given that it's a relatively advanced example not likely to be relevant to someone first learning the language, I suggest simply removing it. A separate section on advanced pattern matching could potentially cover it. Fixes scala-exercises#34
According to https://github.com/scala-exercises/exercises-scalatutorial/blob/master/src/main/scala/scalatutorial/sections/StandardLibrary.scala#L72-L97
the last case of
case List(2 :: xs)
gives error because the inferred type isList[Int]
but the case signature is expectingList[List[Int]]
. Please correct me if I am wrong. If I am not then how should it be re-written?The text was updated successfully, but these errors were encountered: