In addition to what’s been said, how about packages parametrized on packages (or maybe also other language constructs (see below some related thoughts))?
How about another angle at unification? Classes and objects. Is there ever any benefit from having different instances of a class whose ctor takes no arguments? Unless the ctor has side effects the answer might be no, but a side effecting ctor is probably an antipattern anyway. So maybe we could get away with just one language construct for these?
What I don’t know though is what would be an alternative to expressing companion objects.
I’m probably getting carried away a bit here, but all these language constructs we have, packages, classes, objects, but even vals and defs, they right now feel so similar to me. Classes’ bodies are constructors, right? so basically defs. Defs and vals (methods and functions) are mostly interchangeable. All of these can be almost arbitrarily nested. Then the current discussion on packages, classes and objects…
wouldn’t be surprised if much more unification could be done than I originally asked about. Maybe even collapsing it all into a single concept would be possible, but not necessarily that far. Maybe it would even be desirable.
It would be very different though. Still, if it’s practical improvement and simplification and doesn’t cause loss of expressivity I’d be happy to see it happen in say Scala 4. I can imagine it would be.
I can also imagine it wouldn’t. This sounds a bit like I’m going backwards and this way we would end up with something like just the core DOT, so that this already exists actually in this way. But I’m not sure if it would be a bad thing, given the amount of similarity between our different language constructs.
It also sounds a bit Lispy, especially blurring the line between data and code, classes (and by extension e.g. ADTs based on classes) and methods or functions. But that line is already blurred, functions are objects, class bodies are ctors… maybe the fact renders some of our syntax redundant and not actually adding expressivity.