Multi-file ADTs #21907
joan38
started this conversation in
Feature Requests
Multi-file ADTs
#21907
Replies: 1 comment 2 replies
-
The use case falls under "prefer composition to inheritance". Delegation to private implementation classes is made trivial by
Instead of "multifile ADT", I think a more generally useful feature would be "multifile compilation unit". That would allow a huge class with its huge companion object to be in two files. (That has been requested previously.) No doubt this could be implemented in a build tool, since the compiler is nominally agnostic about how a compilation unit is sourced. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Here is a proposal to add the
permits
keyword onsealed
traits and classes to allow the implementation of multi file ADTs:This would work similarly to Java 17: https://docs.oracle.com/en/java/javase/17/language/sealed-classes-and-interfaces.html
We have multiple instances were we dropped the sealed keyword just because the file was too big.
Some other are using a trick with traits: https://github.com/BalmungSan/scala-multifile-adt
Thanks
Beta Was this translation helpful? Give feedback.
All reactions