scalaz-plugin icon indicating copy to clipboard operation
scalaz-plugin copied to clipboard

Singleton improvements

Open sir-wabbit opened this issue 7 years ago • 4 comments

Convince Scalac that all instances of a typeclass or a proposition have the same singleton type. Could be crucial for associated types...

~~Convince Scalac that val x = ...; val y = x implies x.type = y.type.~~

sir-wabbit avatar Jun 28 '18 21:06 sir-wabbit

Convince Scalac that val x = ...; val y = x implies x.type = y.type.

You just need to drop the widen for that — but if you extend it to template bodies, that will make val y = x part of the computed APIs and harder to change. And if you don't extend it to bodies, it will make val have context-dependent semantics.

Blaisorblade avatar Jul 27 '18 17:07 Blaisorblade

I am fine with context-dependent semantics, but I would prefer x.type = y.type to be visible only within the scope / package / file / module. The second part of this issue is not really important and mostly just for convenience in some very rare cases, so let's just drop it.

sir-wabbit avatar Jul 27 '18 21:07 sir-wabbit

IMO there's another thing to solve, which is making x.type#A equal Y#A when Y <: Singleton if x: Y. This is only a problem because of null; I think it's safe to assume that if you're using singleton types with type projections deliberately, null isn't likely a problem for you.

edmundnoble avatar Sep 13 '18 03:09 edmundnoble

@edmundnoble Even better, make x.type = Y when Y <: Singleton if x: Y, which is stronger. I filed this as https://github.com/lampepfl/dotty/issues/4583 and https://github.com/scala/bug/issues/10905 (and it looks fixable on Dotty). Good points on null (speculation on Dotty in https://github.com/lampepfl/dotty/issues/4583#issuecomment-420875019).

Blaisorblade avatar Sep 13 '18 03:09 Blaisorblade