My 2 penith.
I repeatedly hit the need for some “import for export” semantics. The most common thing is if something is declared within a companion object, but needs to be visible at the package level. The second most common is when something is declared deep down in a nested package and needs to be provided as a default when you import the top level package – this happens a lot in the Scala collections.
Let’s look at a sketch of an example:
package bioinf
opaque type DNA = String
object DNA {
def (s: String) toDNA: DNA = {
assert(s.forAll("agct" contains _))
s
}
}
// pulls DNA.toDNA to be visible in the top-level scope
import for export DNA.toDNA
So we can now write things like:
// import everything in the bioinf top-level scope, including the exports
// so equivalent to import {bioinf._, bioinf.DNA.toDNA}
import bioinf._
"gattaca".toDNA
Currently to make this work we either need a bunch of imports to pull things out of the various objects, or we have to put something top-level in the package e.g . fake types and companion objects. This causes havoc with implied
instances, and is a maintenance pain. Adding aliases alters the semantics, as you have to include extra vals/types to shadow in the underlying types.