Consider implicit Base #1522

Closed
pao opened this Issue Nov 9, 2012 · 7 comments

4 participants

@pao
The Julia Language member
pao commented Nov 9, 2012

I believe we've briefly gone over this before, but since it's the Month of Chaos I'd like it to be made as an explicit decision.

Lots of Julia is implemented as pure Julia in the Base module. This means that lots of the useful bits of the language are only accessible in a module that has a using Base statement, such that nearly every module will end up needing a using Base.

Given:

  1. Julia will need to be usable by technical non-programmers,
  2. Much of what we would consider the core Julia language is in Base,
  3. The Main module already implicitly loads Base

I would suggest that all modules should implicitly open with using Base, unless some escape mechanism (TBD, but cf. GHC's NoImplicitPrelude) is used to prevent that from occurring.

If nearly every module needs it anyways, it seems like the sort of thing that will just annoy the heck out of people for no good reason.

@JeffBezanson
The Julia Language member

This is totally reasonable, it just always struck me as ugly to have a not using mechanism just for this purpose. But if somebody has a good syntax idea for this I will implement it.

@mlubin
The Julia Language member

I second this and also question why, for example, import Base.(+) is needed if we implement (+) for a custom type. Seems like it creates unnecessary clutter and potential confusion.

@JeffBezanson
The Julia Language member

The reason is that you could write function foo(...) intending to create a new, private function, not realizing that there is actually a foo in Base that you'd be modifying.

@nolta
The Julia Language member

using !Base?

@mlubin
The Julia Language member

Seems like that would be a small minority of the cases, but it is a bit strange syntactically that methods are automatically exported if they modify an existing method, but otherwise aren't. It would be more consistent to modify an existing method from another module only if you list the local function in export. Not sure how difficult that would be to implement.

@mlubin
The Julia Language member

exclude Base is legible and maybe wouldn't need to be a restricted keyword if it only has a special meaning right after the module line.

@pao
The Julia Language member
pao commented Nov 9, 2012

Just for reference, the Haskell equivalent to a "skip Base"/"use part of Base" syntax:

{-# LANGUAGE NoImplicitPrelude #-}
-- one could also use import Prelude (), though I understand that's subtly different

-- then maybe (roughly equivalent to current Julia `import Base`)
import qualified Prelude
-- or possibly (no obvious Julia equivalent)
import qualified Prelude as P
-- or even (no current Julia equivalent)
import Prelude hiding (zip, foldr)

Of course the latter two import statements would be useful even outside the context of Base.

@JeffBezanson JeffBezanson was assigned Nov 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment