I'm reviving this thread because the enum
as namespace thing bugs me every time, and I think this proposal covers the issue really well. There are other threads on this topic too, and AFAICT the arguments against mostly boil down to "let's avoid adding more keywords". But I think the differences between enum
and the proposed namespace
are valuable.
For example, this nonsense compiles:
enum MyNamespace { ··· }
protocol Silliness
{
func impossible() -> MyNamespace
}
There may be cases where an uninhabited enum makes sense as a return type (like Never
, of course), but not for one that's supposed to be a namespace, and I want to be able to express that.
As proposed, a namespace
is mostly a more restricted version of an enum
, except for being able to include protocols. If this were to be implemented, what are the potential complications of allowing nested protocols?