Pre-SIP: sealed enumerating allowed sub-types

Yes, it’s just an idea. Currently you can’t compile a directory. Dotty complains, and Scala 2 pretends it can’t find it. My suggestion was to name the directory foo.scala to indicate that it must be compiled as a multi-file unit. In other respects, the files would be ordinary sources.

Now I’ve got to hurry and work up an implementation to SIP it in time for Scala 3.

1 Like

Having directories with names that look like filenames will confuse people

1 Like

Coming from here, I can identify with many arguments, namely that

  • sealed (A, B, C, D) trait T { ...} is a very elegant solution (I suggested an annotation, which implies no change needed to the parser)
  • the main issue with sealed is the artificial restriction to put everything into one file, and this can get messy and be a lot of work to join, so that eventually you do not seal types that should be sealed in order to get exhaustive pattern matching
  • the Scala 3 union self-type is not a replacement for sealed traits; it looks very contrived and unclear
  • I disagree with Martin that the one-file-problem is solved by mixing in implementation traits that live in other files. First of all, they become visible. Second, they don’t solve the problem of huge companion objects that carry all sorts of serializers, type class instances etc.

I think such SIP would be very useful.

7 Likes