# How can I get value from literal singleton types?

**URL:** <https://contributors.scala-lang.org/t/how-can-i-get-value-from-literal-singleton-types/1312>\
**Category:** Dotty\
**Created:** [November 14, 2017, 3:41am UTC](https://contributors.scala-lang.org/t/how-can-i-get-value-from-literal-singleton-types/1312 "2017-11-14T03:41:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glavo](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/glavo/32/3227_2.png) [@Glavo](https://contributors.scala-lang.org/u/Glavo)\
**Post date:** [November 14, 2017, 3:41am UTC](https://contributors.scala-lang.org/t/how-can-i-get-value-from-literal-singleton-types/1312/1 "2017-11-14T03:41:17Z")

</div>

How do I get the value it corresponds to when I have a literal singleton type?

---

<div class="post-metadata">

**Author:** ![tpolecat](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/tpolecat/32/41_2.png) [@tpolecat](https://contributors.scala-lang.org/u/tpolecat)\
**Post date:** [November 14, 2017, 7:56pm UTC](https://contributors.scala-lang.org/t/how-can-i-get-value-from-literal-singleton-types/1312/2 "2017-11-14T19:56:05Z")

</div>

With [Typelevel Scala](https://github.com/typelevel/scala/blob/typelevel-readme/notes/typelevel-4.md) you can use `ValueOf`.

```scala
scala> def foo[A: ValueOf]: A = valueOf
foo: [A](implicit evidence$1: ValueOf[A])A

scala> foo[42]
res0: Int = 42

scala> val a = 1
a: Int = 1

scala> foo[a.type]
res1: a.type = 1

```

With Lightbend Scala I believe you have to use something like `shapeless.Witness` to materialize the value.

Of course I may have misunderstood the question. If you’re in macro land I have no idea.

---

<div class="post-metadata">

**Author:** ![soronpo](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/soronpo/32/533_2.png) [@soronpo](https://contributors.scala-lang.org/u/soronpo)\
**Post date:** [November 15, 2017, 6:09am UTC](https://contributors.scala-lang.org/t/how-can-i-get-value-from-literal-singleton-types/1312/3 "2017-11-15T06:09:30Z")

</div>

There is an open issue for dotty to add `ValueOf`

> <https://github.com/lampepfl/dotty/issues/2857>
>
> SIP23 will be merged into Scala 2.xx sometime in the future (currently merged into TLS).
> Its implementation has a ValueOf type class...
