Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-10 Thread Hooman Mehr via swift-evolution
As Braeden notes, the same compiler magic already works for most standard library container / monadic types. It could probably work in more cases. Let me clarify what I meant: This compiler magic is a very useful machinery that already exists and although the use cases are not wide enough to

Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-10 Thread Braeden Profile via swift-evolution
I did some experimenting, and I see that most variance situations are covered by the compiler. Generic collections and wrappers, like Optional or Array, are acceptable with .map and .flatMap, but currently benefit from compiler magic to cast those types. However, not all the standard library

Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-10 Thread David Waite via swift-evolution
I wouldn’t keep it that narrow - monadic types like Optional also benefit from variance: func p(_ data:Any?) { if data != nil { data.map { print($0) } } } var a:String? = "foo" p(a) // -> “foo" -DW > On Dec 9, 2016, at 12:24 PM, Hooman Mehr via swift-evolution >

Re: [swift-evolution] Generic types—covariance/contravariance

2016-12-09 Thread Charles Srstka via swift-evolution
Yes, please. +1. Charles > On Dec 8, 2016, at 6:45 PM, Braeden Profile via swift-evolution > wrote: > > Has the core team or the community considered the possibility of implementing > covariant/contravariant generic types? It would really be appreciated. > > I

Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-09 Thread Paul Cantrell via swift-evolution
Siesta’s Entity would certainly profit from being able to opt in to this mechanism: https://bustoutsolutions.github.io/siesta/api/Structs/Entity.html It is _not_ a collection type and does not implement any

Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-09 Thread Hooman Mehr via swift-evolution
For the specific case of custom collections, I think it is worth providing a protocol as Doug noted before. Quoting Doug Gregor (1/13/16, thread: "Make generics covariant and add generics to protocols”): > Swift’s value-semantic collections are covariant in their generic parameters, > which

Re: [swift-evolution] Generic types―covariance/contravariance

2016-12-09 Thread Robert Widmann via swift-evolution
I keep seeing collections brought up whenever this is discussed, so my question is: Have you found a broader use for variance annotations in the Swift you write? Even in Objective-C (perhaps due to their relative obscurity) I don't see (non-Foundation) people make use of the variance

Re: [swift-evolution] Generic types—covariance/contravariance

2016-12-09 Thread Daniel Leping via swift-evolution
Huge +1 here. To bring powerful functional approach to Swift I strongly feel like it's a must have. Issue demonstration: //co/invariance type typealias FooFun<-A, +R> = (A)->R //current types typealias BarFun = (A)->R func exact(view:UIView) -> UIView func nonexact(view:NSObject) ->

[swift-evolution] Generic types—covariance/contravariance

2016-12-08 Thread Braeden Profile via swift-evolution
Has the core team or the community considered the possibility of implementing covariant/contravariant generic types? It would really be appreciated. I know with Array, vague-ifying or specific-ifying the type ([Int] to [Any]) has help from the compiler—and we can use `map` if all else