Skip to content

Instantly share code, notes, and snippets.

@erikerlandson
Created April 16, 2020 22:47
Show Gist options
  • Save erikerlandson/62d53a7cb0e09583952223ad8dcf898e to your computer and use it in GitHub Desktop.
Save erikerlandson/62d53a7cb0e09583952223ad8dcf898e to your computer and use it in GitHub Desktop.
scala> def foo[T <: Singleton](ce: T)(implicit tt: WeakTypeTag[T]): String = tt.tpe.toString
foo: [T <: Singleton](ce: T)(implicit tt: reflect.runtime.universe.WeakTypeTag[T])String
scala> foo(5)
res37: String = Int(5)
scala> foo("abc")
res38: String = String("abc")
scala> val x = 5
x: Int = 5
scala> foo(x)
res39: String = x.type
@erikerlandson
Copy link
Author

scala> def foo[T <: Singleton](ce: T)(implicit tt: WeakTypeTag[T], w: WitnessAs[T, T]) = (tt.tpe.toString, w.snd)
foo: [T <: Singleton](ce: T)(implicit tt: reflect.runtime.universe.WeakTypeTag[T], implicit w: eu.timepit.refined.internal.WitnessAs[T,T])(String, T)

scala> foo(5)
res0: (String, 5) = (Int(5),5)

scala> val x = 5
x: Int = 5

scala> foo(x)
res1: (String, x.type) = (x.type,5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment