[swift-evolution] [Discussion] Additional generics specialization

Charlie Monroe charlie at charliemonroe.net
Mon Jul 18 02:11:24 CDT 2016


In general, Swift will need a way to point to a generic type without a particular specialization. Currently, you can't do this:

class APICall<T> { }

class CombinedCall: APICall<Bool> {
	var calls: [APICall] // Error - no specialization
}

I've been currently working around this by:

class APICallBase {} // No generics
class APICall<T>: APICallBase {}
class CombinedCall: APICall<Bool> {
	var calls: [APICallBase]
}

But it's definitely a pain to work with.

As asked by the core team several times now, we should defer any discussion on additional features until August.


> On Jul 18, 2016, at 9:04 AM, Adrian Zubarev via swift-evolution <swift-evolution at swift.org> wrote:
> 
> This is something additional, but I’m curios about how the community feels about it.
> 
> I recently come across the issue where conforming to Hashable wasn’t enough to thecke if two instances of the same generic type were equal.
> 
> I had additionally provide myself the != function.
> 
> public func !=<T, U>(lhs: SomeTypeName<T>, rhs: SomeTypeName<U>) -> Bool {
>     return lhs.hashValue != rhs.hashValue
> }
> I wondered if Swift can ever get generic specialization like this:
> 
> public func !=<T : Hashable, U, V>(lhs: T<U>, rhs: T<V>) -> Bool {
>     return !(lhs.hashValue == rhs.hashValue)
> }
> This function in stdlib would fill the gap. Or we need an extra protocol GenericHashable which includes !=.
> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160718/52831f68/attachment.html>


More information about the swift-evolution mailing list