Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created September 2, 2024 14:06
Show Gist options
  • Save nagat01/b8faa0943e989713d5fcf44f3be3263b to your computer and use it in GitHub Desktop.
Save nagat01/b8faa0943e989713d5fcf44f3be3263b to your computer and use it in GitHub Desktop.
import scala.compiletime.summonFrom
trait Show[A]:
def show(a: A): String
given Show[String] with
def show(a: String): String = s"String: $a"
inline def show[A](a: A) = summonFrom:
case show: Show[A] => show.show(a)
case _ => s"Unknown type: $a"
@main def main =
println(show(42))
println(show("Scala 3"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment