[swift-evolution] [SE-0011] Re-considering the replacement keyword for "typealias"

James Campbell james at supmenow.com
Wed Dec 23 06:23:24 CST 2015


>
>
> > In fact why not just use the generics syntax with protocols ?  Anybody
> implementing a "Generic" Protocol has to specify the types.
> That's a simple solution, but inconvenient:
> One use case for placeholders (I don't use the official name here to
> propagate an alternative ;-) is when you have a types that depend on a
> parameter.
> I'm to lazy to look up a real example, but Array<Int> is naturally
> associated with an enumerator for Int — and it is no fun to be forced to
> include such relationships all over the place.


So in my example with placeholders.

class GenericCollection<Type>: Collection<Key: Type, Value: Type>
{

}

Has already specified the type of the placeholder :) so subclasses don't
need to specify it. In this example the Key and Value type placeholders are
bound to whatever the Type is.

So in these examples

let items: GenericCollection<Int> = GenericCollection()

or

let items: [Int] = []

the Key and Value type placeholders would be Ints :) since the generic type
is an Int.


-- 
 Wizard
james at supmenow.com
+44 7523 279 698
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151223/de60879f/attachment.html>


More information about the swift-evolution mailing list