[swift-evolution] Should we rename "class" when referring to protocol conformance?
dabrahams at apple.com
Wed May 4 13:29:10 CDT 2016
on Wed May 04 2016, Adrian Zubarev <swift-evolution at swift.org> wrote:
> Not sure what to think about the enum cases inside a protocol (if AnyEnum would
> even exist), it could be a nice addition to the language, but this is an own
> proposal I guess.
> We should start by adding AnyValue protocol to which all value types
Having a way to constrain conformance to things with value semantics is
something I've long wanted. *However*, the approach described is too
simplistic. It's possible to build classes whose instances have value
semantics (just make them immutable) and it's possible to build structs
whose instances have reference semantics (just put the struct's storage
in a mutable class instance that it holds as a property, and don't do
In order for something like AnyValue to have meaning, we need to impose
greater order. After thinking through many approaches over the years, I
have arrived at the (admittedly rather drastic) opinion that the
language should effectively outlaw the creation of structs and enums
that don't have value semantics. (I have no problem with the idea that
immutable classes that want to act as values should be wrapped in a
struct). The language could then do lots of things much more
intelligently, such as correctly generating implementations of equality.
More information about the swift-evolution