Created
September 2, 2024 12:00
-
-
Save nagat01/13e99fb17d4080da6be75e0953c8052c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| trait Show[T]: | |
| def show(value: T): String | |
| given Show[Int] with | |
| def show(value: Int) = s"Int: $value" | |
| given Show[String] with | |
| def show(value: String) = s"String: $value" | |
| class Printer1[T](value: T)(using ctx: Show[T]): | |
| println(ctx.show(value)) | |
| class Printer2[T: Show](value: T): | |
| println(summon[Show[T]].show(value)) | |
| @main def main = { | |
| Printer1(42) | |
| Printer2("Scala 3") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment