SE-0335: Introduce existential `any`

A good chunk of the debate here centers around whether existentials are a separate, concrete, surface-visible box type of their own, or an implementation detail which is subsumed into the more abstract logic of the type system.

In other words, given this:

let x: any P = T()

…would we say that…

  1. the value x has a P (i.e. is a box that contains a T), or
  2. the value x is a P?

This has been a point of tension in the language, and even within the Swift team itself, at least since I filed this bug in 2016.

The Any<P> counterproposal would seem to lean toward codifying (1): existentials are a programmer-visible box type. The proposed any P syntax certainly leans toward (2), and perhaps I like the proposal because (2) is my preferred mental model. But (2) certainly does raise questions like the ones @jackmarch is asking — and I find myself hard-pressed to come up with answers to his questions that don’t lean at least a little on the “visible box” model of (1).

I really like the feature idea Holly mentions here:

I remember we discussed it here, and IIRC Joe Groff mentioned it at some point before that. I hope that idea will come up for consideration soon! It seems like it could help close the loop on making (2) a workable mental model.

(I should clarify that my +1 for this proposal is not contingent on the future adoption or non-adoption of that future direction.)

6 Likes