typelevel / scala

Typelevel Scala, a fork of Scala
http://typelevel.org/scala/
372 stars 21 forks source link

clean syntax for the _root_ #144

Closed fommil closed 6 years ago

fommil commented 7 years ago

It is no secret that imports are one of the most confusing things about FP libraries and there has been a lot of work to simplify this. However, I'm still finding that it's easy to get confused between relative and absolute paths. How many cats, fs2, implicits or io packages are there now? All the interop imports just make it worse and worse.

We can help ourselves by ensuring we use root-based imports, but it's painfully ugly!

import _root_.io.circe._
import _root_.fs2._
import _root_.cats._

It'd be nice if we cleaned it up a little bit with a symbol alias for _root_. e.g. | or . or / (pick one)

import |io.circe._
import /fs2._
import .cats._

and at the same time, ban the creation of packages named _root_ so that it doesn't end up becoming a relative name!

This could even be done in parser (taking care with Position), just naively rewriting import[\w]+[|/.] to import _root_.

fommil commented 6 years ago

https://contributors.scala-lang.org/t/proposed-syntax-for--root-/1035