[Pitch] Allow sub-protocols to define typealiases for protocols' associatedtypes


(Ross O'Brien) #1

Given a protocol with an associated type:

protocol Foo
{
  associatedtype Bar
}

it should be possible to define a protocol conforming to Foo, for which Bar
can be typealiased:

protocol IntFoo : Foo
{
  typealias Bar = Int
}

such that all conformers to IntFoo now have an associatedtype Bar being Int
without having to define it themselves. At present IntFoo cannot declare a
typealias (as this generates a warning that typealias has been deprecated),
but can declare an 'associatedtype Bar = Int' which types conforming to
IntFoo have to repeat to consider it properly declared. This re-declaration
is redundant.


(Douglas Gregor) #2

The “More Powerful Constraints for Associated Types” proposal provides a better way to accomplish this:

  https://github.com/apple/swift-evolution/pull/284

  - Doug

···

On Jun 6, 2016, at 1:59 PM, Ross O'Brien via swift-evolution <swift-evolution@swift.org> wrote:

Given a protocol with an associated type:

protocol Foo
{
  associatedtype Bar
}

it should be possible to define a protocol conforming to Foo, for which Bar can be typealiased:

protocol IntFoo : Foo
{
  typealias Bar = Int
}

such that all conformers to IntFoo now have an associatedtype Bar being Int without having to define it themselves. At present IntFoo cannot declare a typealias (as this generates a warning that typealias has been deprecated), but can declare an 'associatedtype Bar = Int' which types conforming to IntFoo have to repeat to consider it properly declared. This re-declaration is redundant.


(Xiaodi Wu) #3

Wouldn't this be covered under SE-0092?

···

On Mon, Jun 6, 2016 at 15:59 Ross O'Brien via swift-evolution < swift-evolution@swift.org> wrote:

Given a protocol with an associated type:

protocol Foo
{
  associatedtype Bar
}

it should be possible to define a protocol conforming to Foo, for which
Bar can be typealiased:

protocol IntFoo : Foo
{
  typealias Bar = Int
}

such that all conformers to IntFoo now have an associatedtype Bar being
Int without having to define it themselves. At present IntFoo cannot
declare a typealias (as this generates a warning that typealias has been
deprecated), but can declare an 'associatedtype Bar = Int' which types
conforming to IntFoo have to repeat to consider it properly declared. This
re-declaration is redundant.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution