Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Symbol literals should have useful singleton types #51

Closed
milessabin opened this issue Sep 17, 2014 · 2 comments
Closed

Symbol literals should have useful singleton types #51

milessabin opened this issue Sep 17, 2014 · 2 comments
Assignees

Comments

@milessabin
Copy link
Member

Scala Symbols have first class literal syntax like strings, however unlike string literals Symbol literals lack useful singleton types,

scala> def single[T <: AnyRef](t: T): Option[t.type] = Some(t)
single: [T <: AnyRef](t: T)Option[t.type]

scala> single("foo")
res0: Option[String("foo")] = Some(foo)

scala> single('foo)
res1: Option[Symbol] = Some('foo)

shapeless simulates singleton types for Symbol literals by @@-tagging them with the singleton type of the corresponding string literal. It would be nice, particularly in the light of #15 and #27, to have richer native singleton types for Symbol literals too.

@milessabin milessabin changed the title Symbols should have useful singleton types Symbol literals should have useful singleton types Sep 17, 2014
@propensive
Copy link

I would be very interested in seeing more general support for returning singleton types from user-defined StringContext "literals". This should be possible already using whitebox macros, though if that could be done avoiding all the macro machinery, that would be much preferred.

e.g.

scala> single(uri"http://www.example.com/")
res0: Option[HttpUrl("http://www.example.com/")] = Some(http://www.example.com/)

@propensive propensive self-assigned this Oct 6, 2014
@densh densh mentioned this issue Oct 29, 2014
23 tasks
@milessabin
Copy link
Member Author

This is fixed in the SIP-23 PR which will be included in the 2.12.0-RC1 Typelevel Scala release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants