Yann Moisan
Yann Moisan

Reputation: 8281

How to use literal type in Scala 2.13

I'm trying Literal Types from Scala 2.13 and I encounter the following error :

scala> def double[A <: Singleton] = valueOf[A]
                                           ^
       error: No singleton value available for A.

Could you explain why ?

Upvotes: 1

Views: 2523

Answers (2)

Valy Dia
Valy Dia

Reputation: 2851

I am not entirely sure of what you're trying, but here an example from the doc:

def foo[T](implicit v: ValueOf[T]): T = v.value

A scala.ValueOf[T] type class and corresponding scala.Predef.valueOf[T] operator has been added yielding the unique value of types with a single inhabitant

Upvotes: 2

cchantep
cchantep

Reputation: 9158

I don't think that's working like that, but rather with the related typeclass ValueOf:

object Foo

def foo[A : ValueOf] = valueOf[A]

scala> foo[Foo.type]

res2: Foo.type = Foo$@1c105c3a

Upvotes: 6

Related Questions