I have an issue with using a heterogeneous array of objects conforming to a protocol - I want to write an extension on Array (or CollectionType) that applies only when Element : MyProtocol, but I can’t call methods in that extension from an instance of [MyProtocol] because "Using ‘MyProtocol' as a concrete type conforming to protocol ‘MyProtocol' is not supported”
I’ve asked about this on swift-users (https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html\) and got some good workarounds but no one was able to provide me with information on any future plans in swift to address this issue - whether that’s making protocols conform to themselves, or some other improved approach to heterogeneous collections. I wonder if anyone here can shed some light on this? (I’m new to the mailing lists, sorry!)
I have an issue with using a heterogeneous array of objects conforming
to a protocol - I want to write an extension on Array (or
CollectionType) that applies only when Element : MyProtocol, but I
can’t call methods in that extension from an instance of [MyProtocol]
because "Using ‘MyProtocol' as a concrete type conforming to protocol
‘MyProtocol' is not supported”
Hint: write your extension so it applies when Element == MyProtocol instead.
···
on Tue Mar 29 2016, Jason Sadler <swift-evolution@swift.org> wrote:
I’ve asked about this on swift-users
(https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html\)
and got some good workarounds but no one was able to provide me with
information on any future plans in swift to address this issue -
whether that’s making protocols conform to themselves, or some other
improved approach to heterogeneous collections. I wonder if anyone
here can shed some light on this? (I’m new to the mailing lists,
sorry!)
I have an issue with using a heterogeneous array of objects conforming
to a protocol - I want to write an extension on Array (or
CollectionType) that applies only when Element : MyProtocol, but I
can’t call methods in that extension from an instance of [MyProtocol]
because "Using ‘MyProtocol' as a concrete type conforming to protocol
‘MyProtocol' is not supported”
Hint: write your extension so it applies when Element == MyProtocol instead.
Why don't we also imply `Element == MyProtocol` when using `Element: MyProtocol` ?
Both extensions can have the exact same functions/implementation.
Am I missing something?
I currently don't see why we are forced to distinguish between homogeneous and heterogeneous Collections.
Kind regards
- Maximilian
···
Am 31.03.2016 um 20:14 schrieb Dave Abrahams via swift-evolution <swift-evolution@swift.org>:
on Tue Mar 29 2016, Jason Sadler <swift-evolution@swift.org> wrote:
I’ve asked about this on swift-users
(https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html\)
and got some good workarounds but no one was able to provide me with
information on any future plans in swift to address this issue -
whether that’s making protocols conform to themselves, or some other
improved approach to heterogeneous collections. I wonder if anyone
here can shed some light on this? (I’m new to the mailing lists,
sorry!)
I have an issue with using a heterogeneous array of objects conforming
to a protocol - I want to write an extension on Array (or
CollectionType) that applies only when Element : MyProtocol, but I
can’t call methods in that extension from an instance of [MyProtocol]
because "Using ‘MyProtocol' as a concrete type conforming to protocol
‘MyProtocol' is not supported”
Hint: write your extension so it applies when Element == MyProtocol instead.
Why don't we also imply `Element == MyProtocol` when using `Element: MyProtocol` ?
Both extensions can have the exact same functions/implementation.
Am I missing something?
I currently don't see why we are forced to distinguish between homogeneous and heterogeneous Collections.
To some degree this is an implementation limitation; right now our type checker has the silly limitation that the MyProtocol type is *never* considered to conform to the MyProtocol protocol. However, there are cases where this is formally impossible. If MyProtocol has static method or initializer requirements, or uses the `Self` type in argument position, then the MyProtocol type can't be a model of its own protocol without additional work.
-Joe
···
On Apr 1, 2016, at 8:17 AM, Maximilian Hünenberger via swift-evolution <swift-evolution@swift.org> wrote:
Am 31.03.2016 um 20:14 schrieb Dave Abrahams via swift-evolution <swift-evolution@swift.org>:
on Tue Mar 29 2016, Jason Sadler <swift-evolution@swift.org> wrote:
I’ve asked about this on swift-users
(https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html\)
and got some good workarounds but no one was able to provide me with
information on any future plans in swift to address this issue -
whether that’s making protocols conform to themselves, or some other
improved approach to heterogeneous collections. I wonder if anyone
here can shed some light on this? (I’m new to the mailing lists,
sorry!)
I have an issue with using a heterogeneous array of objects conforming
to a protocol - I want to write an extension on Array (or
CollectionType) that applies only when Element : MyProtocol, but I
can’t call methods in that extension from an instance of [MyProtocol]
because "Using ‘MyProtocol' as a concrete type conforming to protocol
‘MyProtocol' is not supported”
Hint: write your extension so it applies when Element == MyProtocol instead.
Why don't we also imply `Element == MyProtocol` when using `Element:
MyProtocol` ?
Because Element == MyProtocol is more restrictive; it doesn't allow
arbitrary types that conform to—but are not—MyProtocol.
···
on Fri Apr 01 2016, Maximilian Hünenberger <swift-evolution@swift.org> wrote:
Am 31.03.2016 um 20:14 schrieb Dave Abrahams via swift-evolution <swift-evolution@swift.org>:
on Tue Mar 29 2016, Jason Sadler <swift-evolution@swift.org> wrote:
Both extensions can have the exact same functions/implementation.
Am I missing something?
I currently don't see why we are forced to distinguish between homogeneous and heterogeneous Collections.
I’ve asked about this on swift-users
(https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160321/001560.html\)
and got some good workarounds but no one was able to provide me with
information on any future plans in swift to address this issue -
whether that’s making protocols conform to themselves, or some other
improved approach to heterogeneous collections. I wonder if anyone
here can shed some light on this? (I’m new to the mailing lists,
sorry!)