Skip to content

fix errors of code in "Explicit term inference" article #1178

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _posts/2020-11-06-explicit-term-inference-in-scala-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ The second step was to define the extension method which relies on two implicits
```scala
// ShowOps.scala
object ShowOps {
implicit class showOps[A](in: A) extends AnyVal {
implicit class showOps[A](private val in: A) extends AnyVal {
def show(implicit instance: Show[A]): String =
instance.show(in)
}
Expand All @@ -386,7 +386,7 @@ object Show {

// Either this or import ShowOps and use context bound
implicit def showList[A](ls: List[A])(implicit instance: Show[A]) =
ls.map(instance.show).mkList(",")
ls.map(instance.show).mkString(",")
}
```
which brings us to the main definition:
Expand All @@ -399,7 +399,7 @@ case class Mountain(name: String, height: Int)

object Main extends App {
implicit val mountainShow: Show[Mountain] =
Show.fromFunction((m: Mountain) => s"The ${m.name} is ${m.height} meters high")
Show.from((m: Mountain) => s"The ${m.name} is ${m.height} meters high")
Copy link
Author

@vitojeng vitojeng Nov 17, 2020

Choose a reason for hiding this comment

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

Compare with the line 383, the method name should be from


val mountains = List(Mountain("Mont Blanc", 4808), Mountain("Matterhon", 4478))
println(mountains.show)
Expand Down