Skip to content

Coding example of "Variances" corrected #1654

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 5 commits into from
Apr 30, 2020
Merged

Conversation

andreamarconi
Copy link
Contributor

@andreamarconi andreamarconi commented Mar 10, 2020

The coding example inside the Variances (both in Covariance and Contravariance) wasn't completely working (as reported in #1533 ) , even if the proposed solution could be unelegant it should make possible for everyone to try it on their own platform.

@SethTisue
Copy link
Member

is there someone watching this repo who could review this...?

@martijnhoekstra
Copy link
Contributor

The original code works, but not in a REPL.

This is a rather roundabout way to make it work. Just remove the enclosing objects that extend App instead.

@@ -38,23 +38,20 @@ In the following example, the method `printAnimalNames` will accept a list of an

```tut
object CovarianceTest extends App {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just eliminate the object instead of selecting from it

@@ -87,18 +84,15 @@ If a `Printer[Cat]` knows how to print any `Cat` to the console, and a `Printer[

```tut
object ContravarianceTest extends App {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just eliminate the object instead of selecting from it

@SethTisue
Copy link
Member

@andreamarconi interested in responding to the review feedback?

@andreamarconi
Copy link
Contributor Author

@SethTisue no it's perfectly clear now, i tried the code without using a REPL and work perfectly

@SethTisue SethTisue self-assigned this Apr 30, 2020
@SethTisue
Copy link
Member

I've added some commits that get CI passing.

@martijnhoekstra I'm confused about where the actual fix is here. I must be missing something that's right in front of my face. wouldn't your suggestion just take us back to the original code?

@martijnhoekstra
Copy link
Contributor

@SethTisue the issue is that this doesn't work in the repl, because extends App doesn't execute in the repl.

The easy fix is to remove the entire enclosing object, including the extends App. i.e. go from

object ContravarianceTest extends App {
  val myCat: Cat = Cat("Boots")

  def printMyCat(printer: Printer[Cat]): Unit = {
    printer.print(myCat)
  }

  val catPrinter: Printer[Cat] = new CatPrinter
  val animalPrinter: Printer[Animal] = new AnimalPrinter

  printMyCat(catPrinter)
  printMyCat(animalPrinter)
}

to plain

val myCat: Cat = Cat("Boots")

def printMyCat(printer: Printer[Cat]): Unit = {
  printer.print(myCat)
}

val catPrinter: Printer[Cat] = new CatPrinter
val animalPrinter: Printer[Animal] = new AnimalPrinter

printMyCat(catPrinter)
printMyCat(animalPrinter)

@SethTisue
Copy link
Member

oh, I was confused, I thought this PR was the one to introduce the wrapper in the first place, but I see now that it wasn't

andreamarconi and others added 5 commits April 30, 2020 08:37
The coding example inside the Variances (both in Covariance and Contravariance) wasn't completely working, even if the proposed solution could be unelegant it should make possible for everyone to try it on their own platform.
tut doesn't like the last line to be a comment, apparently.
I'm not even going to report the problem upstream given
that tut is deprecated anyway, the author recommends people
switch to mdoc
@SethTisue SethTisue merged commit 17557b3 into scala:master Apr 30, 2020
@SethTisue
Copy link
Member

thank you Andrea and Martijn!

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