[swift-evolution] [SE-0011] Re-considering the replacement keyword for "typealias"
James Campbell
james at supmenow.com
Wed Dec 23 05:26:08 CST 2015
In fact why not just use the generics syntax with protocols ? Anybody
implementing a "Generic" Protocol has to specify the types.
protocol Collection<Key, Value >
{
func get(key: Key) -> Value?
}
class StringCollection: Collection<Key: String, Value: String>
{
}
class GenericCollection<Type>: Collection<Key: Type, Value: Type>
{
}
On Wed, Dec 23, 2015 at 11:18 AM, James Campbell <james at supmenow.com> wrote:
> Maybe you could use the phrase "placeholder" type. If you think about it.
> typealias is a way of "aliasing" the type. i.e "Type B is just another name
> for Type C"
>
> Associated type I always found a bit confusing, associated with what ? A
> placeholder type I feel explains it more plainly. Associated types are
> nothing but placeholders.
>
> So this is my example:
>
> protocol Collection
> {
> typeplaceholder T
>
> func first() -> T?
> }
>
> class IntCollection: Collection
> {
> typeplaceholder T = Int
> }
>
> potentially you could provide some sort of syntax for setting it in the
> subclass part of the code.
>
>
> protocol Collection
> {
> typeplaceholder T
>
> func first() -> T?
> }
>
> class IntCollection: Collection<T:Int> //The T type placeholder is now an
> Int
> {
>
> }
>
> class GenericCollection<F>: Collection<T:F> //The T type placeholder is
> now what ever the generic F is set to.
> {
>
> }
>
> On Wed, Dec 23, 2015 at 11:00 AM, Tino Heth via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>>
>> > "Associated type" is the name of this feature
>> The name of the concept is highly inexpressive, and I guess it's far
>> easier to change the docs than to change the language…
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
>
>
> --
> Wizard
> james at supmenow.com
> +44 7523 279 698
>
--
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/225c22c1/attachment.html>
More information about the swift-evolution
mailing list