Sent from my iPad

> On May 26, 2016, at 2:49 PM, Austin Zheng via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> I alway enjoy hearing your ideas.
> 
> This is quite interesting. It's basically a way to define an ad-hoc interface 
> that a type doesn't need to explicitly declare it conforms to. I know Golang 
> works similarly; if a Go type implements all the requirements of an interface 
> it conforms automatically.
> 
> There are positives and negatives to allowing this sort of ad-hoc interface.

Agree.  It would definitely make the language "feel" a bit more fluid.  But it 
doesn't add any expressive power and could have undesirable consequences.

> This would make for a good standalone proposal -- both because it's complex 
> enough to deserve its own discussion, and because if the community is 
> interested someone would have to work through all the implications in order 
> to put together a proposal. It would be quite a big change.

I don't see how this is different from a protocol other than the lack of 
requirement to declare conformance explicitly.  The need to explicitly declare 
conformance is a design decision that I believe the core team feels pretty 
strongly about.  

That said, it hasn't been debated by the community yet so if someone feels 
strongly about dropping explicit conformance declarations it might be worth 
pitching the idea, if for not other reason than to have a discussion about it 
on the lost.

> 
> Best,
> Austin
> 
>> On Thu, May 26, 2016 at 11:56 AM, Adrian Zubarev via swift-evolution 
>> <swift-evolution@swift.org> wrote:
>> I’d like to throw one idea of mine in the room I couldn’t stop thinking when 
>> I read one of Thorsten’s replies on SE–0095 review thread.
>> 
>> This wiki section explains the existential types where we have something 
>> like this:
>> 
>> "T = ∃X { a: X; f: (X → int); } This could be implemented in different ways; 
>> for example:
>> 
>> intT = { a: int; f: (int → int); }
>> floatT = { a: float; f: (float → int); }
>> We discussed how we could create existential types with constraints for 
>> protocols and classes so far. Such an existential can’t create something 
>> like in the example above.
>> 
>> I’m not sure if we need this at all, I’d say it’s a nice to have idea of 
>> mine.
>> 
>> To solve this we could introduce a new scope similar to protocols today but 
>> without the need to explicitly conform types to this existential.
>> 
>> // the above example can become
>> existential T {
>>     associatedtype X
>>     var a: X
>>     func f(_ value: X) -> Int
>> }
>> 
>> struct A /* no explicit conformance to T needed */ {
>>     var a: Int
>>     init(a: Int) { self.a = a }
>>     func f(_ value: Int) -> Int { return value }
>> }
>> 
>> let store: T = A() // this could or should work, just because we do have 
>> visibility to all constraints from T in A here
>> 
>> // if we had `private var a: Int` in A we wouldn't be able to store A inside 
>> `store`
>> I din’t though if existential could have potential to replace Any<…> 
>> completely. Until now I just wanted to solve that particular issue so please 
>> don’t judge with me. :)
>> 
>> Just because of associated types we won’t be able to use store in this 
>> example, but there might be more trivial examples where one would use such 
>> existential type (for only visible portion at compile or dynamically at 
>> run-time) without explicit conformance.
>> 
>> struct B {
>>     var x: Int = 42
>>     var y: Double = -100.5
>> }
>> 
>> struct C: SomeProtocol {
>>     var y: Double = 0.0
>>     var x: Int = 10
>> }
>> 
>> existential SomeShinyThing {
>>     var x: Int
>>     var y: Double
>> }
>> 
>> // we should be safe here because the compiler has visibility for  
>> // internal B and C here
>> let anotherStore: SomeShinyThing = B() /* or */ C()  
>> 
>> // otherwise one could use dynamic casts
>> if let thirdStore = instanceOfCShadowedAsSomeProtocol as? SomeShinyThing { … 
>> }
>> Feel to tear this idea apart as you want. :D
>> 
>> 
>> 
>> -- 
>> Adrian Zubarev
>> Sent with Airmail
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to