6

What's the difference between something being defined in the scala package object and in Predef?

Is Predef just a relic from pre-2.8 when package objects didn't exist, or is there some other reason why we need both?

Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180

1 Answers1

4

According to the ScalaDoc,

"The Predef object provides definitions that are accessible in all Scala compilation units without explicit qualification"

So, it is not a package object itself, but acts as one in terms of providing functionality to "all Scala compilation units"

As for why the situation exists, I think you are right, looks to be a legacy issue

As for why it persists, there may continue to be limitations of package objects that prevent PreDef from being merged.

virtualeyes
  • 11,147
  • 6
  • 56
  • 91
  • I wonder if there are any concrete examples of things in Predef that couldn't go in the scala package object – Luigi Plinge Apr 16 '12 at 16:10
  • Predef may very well work as a package object, but there must be a reason why Scala core devs have chosen to keep Predef as a non-package object if that is the case. A clue in Predef is: "scala.`package` // to force scala package object to be seen". There must be an "import Predef._" provided by the compiler that gives us functionality we would otherwise not get were Predef a package object. Anyway, I bet the scala-lang user group would be able to shed some light on the issue... – virtualeyes Apr 16 '12 at 17:37