Proposed syntax for _root_


My friend made a compiler plugin for the syntax you propose (except it uses ⊢ instead of a dot): ohnosequences/contexts. For example:

def bar(f: (Int, Int) => Int) = foo ⊢ { 
  f(a, b) + c 

With exactly the same meaning as you propose: { import foo._; ... }


Judging by the likes and the comments, the following next steps look like the best way to move this initiative forward:

  • Make _root_ a keyword once and for all.
  • Lobby with Intellij and language servers to prettify _root_.

It seems that the idea of the tree import has gained some traction and, after a while thinking about it, it now seems reasonable. A plus that hasn’t been discussed is that will minimize GitHub diffs if it is combined with trailing commas.

I’ll write two SIPs for these changes. If anybody wants to join me, ping me.


There was a pretty active discussion about this topic… some time ago. :slight_smile:


Note that everyone uses imports incorrectly.

You can’t use util unqualified without an import because it is always imported by scala._, modulo -Yno-imports. Cf this example.

Here’s another example from scaladoc of egregious relative imports. There are packages model.diagram and page.diagram, not quite sibling but like cousins once removed. We’re in package page. For

import model._ ; import model.diagram._ ; import diagram._

it was relying on a bug to prefer page.diagram to the imported model.diagram. I prefer the corrected behavior, because I can’t tell by looking at the code that there is any such package page.diagram, and also the relative imports as shown are confusing to me anyway.

If voting is still open on the previous discussion, I like tree syntax and also the expression syntax. I don’t like having to add braces to accommodate an extra import x._. Even better if it desugars to stabilizing

{ val v = x ; import v._ ; body }


Then what about going full-in and add the underscore for relative imports?

import fully.qualified._

even though for object and local imports it starts to get clunky

def foo(a: Foo) = {
  import _.a._

import _.Bar._
object Bar


That would make it impossible to use relative imports in sources cross-built across 2.12-2.13/2.14. Ideally, any changes should be 100% backwards compatible and not prohibit cross-building.