+
Skip to content

Imports need namespaces (and more) #31

@arendsee

Description

@arendsee

Currently Morloc can currently either import specific values by name or import all values from a module, e.g.:

import foo  -- import everything
import bar (f, g, h as h2) -- import specific things, with optional aliases

In Python, the first line above would instead import the foo namespace where values would be accessed by the dot operator, e.g.,

import math
math.sqrt(4)

This makes sense for short module names. For long module names you can use an alias (e.g., import math as m).

Python also allows exporting specific functions, e.g.,

from math import sqrt

I don't actually like this because it parses backwards to me. I usually make the decision to import math before I've decided how. So I write import math, then have to backtrack to add from. Minor quibble, I know. Also, if I sort my Python lines, I'd prefer to see all the imports together ordered by module.

In Haskell, where module names are often long, the default is to import everything, for example:

import Control.Monad.State -- import everything
import qualified Control.Monad.State as CMS -- import under a namespace
import Control.Monad.State (get) -- import specific function
import Control.Monad.State hiding (get) -- import everything BUT a specific function

This approach also suffers from having qualified before the module names which again messes up the sort.

I sort of lean towards this:

import foo (*) -- export everything
import foo (a, b, c as f)  -- 
import foo as f  -- define a namespace

But this is just syntax. Imports in Morloc need to be MUCH more sophisticated. An import statement should be a query against a function database. It should be able to select languages by language and other metadata.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载