-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Singleton bound and type projections don't play nice with each other #4583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is there a clear statement of the intended semantics of type projections, in Dotty or in DOT? My intuitions in Scala were always that |
Nothing fully satisfactory, but something exists — the 2003 nuObj paper is a good starting point and describes the intended semantics, but some of its rules break down in the presence of lower bounds. What's below are pretty educated guesses. DOT has no type projections, which is why I didn't state my guess, but the Scala 2 implementation is supposed to be based on nuObj, the calculus in A Nominal Theory of Objects with Dependent Types, which does have type projections (called type selection). nuObj has no lower bounds, which avoids all the bad bounds issues in DOT, so type projections were no problem at all. Then the SLS 3.5.1 and 3.5.2 have cases for type projections. 3.5.1 is vague but can be read correctly.
My intuition/conjectures agree, but it's neither EDITED: Instead, Formally, the crucial rules in the nuObj paper are (Alias-=) in Sec. 4.2, (Tsel-\prec (strange <)) in 4.3, (Tsel-<:) in 4.4. They all refer to membership in (Other-\in) in Sec. 4.1, which does introduce an existential |
By |
@milessabin That's what I meant but miswrote, I tried to edit the paragraph to clarify. Proposed new clauses:
SLS 3.5.2:
BTW, the above seems to also work for Scala 2 nested classes, tho I haven't thought about that as much and they definitely don't fit the DOT semantics of type members. |
I think the switch from conforms to equivalent helps here, otherwise I could imagine doing bad things with (empty) intersections of singletons. And, yes, I agree that if |
Yeah that seems uncontroversial. Actually, spelling out that rule is unnecessary, because the SLS declares equivalence to be a "congruence" — while the spec explanation is cryptic, congruence does mean that The tricky question that stands is whether |
@Blaisorblade Yes, that works: type || [A, B] = A | B
type Boo = 0 || 1 |
scalaz/scalaz-plugin#17 requests a similar feature and points out problems with Since we plan to forbid |
I've met similar problem on scala 2.12 and have a dirty workaround for it: https://gist.github.com/pshirshov/1273add00d902a6cfebd72426d7ed758 So I'm wondering if it may be improved in dotty. |
That is correct — if In fact, In this case, it seems type projections are also pretty confusing; In your |
In fact, this is already allowed in Dotty. |
Most of this issue discusses type projections in general — so the semantics proposed at lampepfl/dotty-feature-requests#14 (comment) is relevant. In this proposal, a value In particular, unlike I thought, type projections are indeed covariant, per SLS 3.5.2:
However, I now wonder about SLS 3.2.12; that suggests that |
If a value
tasty
has abstract typeT
andT
is marked as being a singleton type (that is, currently,T <: Singleton
), I’d expecttasty.type = T
, because both types are singleton that containtasty
. This currently fails in Scalac and Dotty (the Scala report is scala/bug#10905 — this is a copy, with Scalac output swapped with Dotty output).A minimized example:
/cc @milessabin
Background
I ran into this while prototyping a heavily path-dependent API in Dotty (an early version of Tasty reflection), in relation to https://github.com/lampepfl/dotty/pull/4577/files/b315dbfa9f2d206cc26da75779388fca98faaabd#r191016341; the workaround involved turning defs into vals, which I suspect is acceptable here but potentially annoying when trying to save memory.
Alternatives
For the example above, enabling the definition of idempotent methods might be more general, if we ever get there.
Soundness
Not formally investigated, since nobody yet added to DOT either singleton types, type projections or singleton type variables.
The text was updated successfully, but these errors were encountered: