This is a proposal for a syntax sugar for module imports that I think would fix most (all?) of the pain points of importing modules as well as potentially enable a decent solution to purescript#2437.
- Module names are very long.
- Modules are imported as unqualified by default. At the moment it wouldn’t make sense to qualify modules by default because of the point above - module names are too long, they need to be explicitly shortened anyway if you plan on using them in a qualified sense.
- If you want to expose something from a module (e.g. types) but use the rest of it qualified, you need to import the module twice.
import from Control.Monad Reader (ReaderT(..), ask, runReaderT) Writer (WriterT(..), runWriterT, tell) import from Data Array Maybe (Maybe(..), maybe, fromMaybe) String Tuple (Tuple(..))
import Control.Monad.Reader (ReaderT(..), ask, runReaderT) import Control.Monad.Reader as Reader import Control.Monad.Writer (WriterT(..), runWriterT, tell) import Control.Monad.Writer as Writer import Data.Array as Array import Data.Maybe (Maybe(..), maybe, fromMaybe) import Data.Maybe as Maybe import Data.String as String import Data.Tuple (Tuple(..)) import Data.Tuple as Tuple
This would also allow this idea regarding making it a convention that modules in packages start with module-name-ified version of their package name much more palatable, as one may only have to write it once
import from MyModule SubModule1 SubModule2 SubModule3
instead of having something extra to tack on to the name of every import.
- Use something different than
import from, e.g.
- Use some form of brackets and separator, e.g.
(,), instead of whitespace and newlines.
- Allow an
import ... asstatment inside the
import fromstatement so you can change the name of the qualified import.
- Have some syntax for nesting, e.g.
import from Control Apply Bind from Monad Reader Writer