[swift-evolution] [Pitch] Remove associated type inference

Dmitri Gribenko gribozavr at gmail.com
Wed May 25 16:47:46 CDT 2016


On Wed, May 25, 2016 at 2:43 PM, David Hart via swift-evolution
<swift-evolution at swift.org> wrote:
> Impact on Existing Code
>
> This is a breaking change that will require conforming types which relied on
> the inference, including in the Standard Library, to explicitly declare
> associated types. A Fix-It could be introduced to add the typealias and
> leave the type to be filled in. That way, all the type inference could be
> removed from the compiler.

Please show an example -- for example, what a smallest collection type
will look like.

> Alternatives Considered
>
> The only alternative is to keep the inference with the known consequences on
> the compiler.

Sorry, that's not fair :)  There is a middle ground -- limited
inference.  For example, in Collection, we don't need Index to be
inferrable from every declaration that mentions it.  We can add a
feature to declare that the type of 'var startIndex' infers
'associatedtype Index' (via an appropriate attribute).  It is true
that this approach would not remove global inference as such, but it
will make it a much easier problem I believe.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/


More information about the swift-evolution mailing list