Regards (From mobile)
> On Jul 18, 2016, at 9:04 AM, Adrian Zubarev via swift-evolution > <[email protected]> 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) > } I am not sure about the ordering... Interestingly enough, this is real code written last week as part of a framework: Export function newSataStore<T extends DataStore<U>, U> (ctor: { new (config:DataStoreConfig):T, config:DataStoreConfig):T { return new ctor(config) } And this is legal code just to try: interface Hashable { getHash(): number } interface T extends Hashable { } class SomeTypeName<Type extends Hashable> { public getHash():number { return ...; } public type():this { return Type; } } function compare<T1 extends T, T2 extends T>(lhs:SomeTypeName<T1>, rhs:SomeTypeName<T2>):boolean { return lhs.getHash() != rhs.getHash(); } but this is more interesting: type List<T> = T & { next: List<T> } // listObj.next.next.next.??? > 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 > [email protected] > https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
