xwu
(Xiaodi Wu)
April 9, 2021, 3:59pm
2
1oo7:
Note: if anyone has already suggested this within the last 2 years, I couldn't find it. If it was suggested before then, and I somehow missed it, please reply with a link, and accept my apologies in advance.
Self-conformance of protocols has been suggested actually many times. For example, @Jumhyn explicitly referenced your other thread in launching a discussion:
Since the topic of self-conforming protocols has been brought up a couple times this week, I thought it would be good to start a separate discussion to determine whether this problem is worth addressing directly. The main motivation, to borrow some examples from @bjhomer , is to allow the following to compile:
protocol Animal {}
struct Cat: Animal {}
struct Dog: Animal {}
// A variable of type 'Animal' is an existential; it can hold *any* Animal
var anyAnimal: Animal
anyAnimal = Cat()
anyAnimal…
4 Likes