Gregofi / mjolnir

Functional programming language without exotic syntax, written in Rust.
2 stars 0 forks source link

Rework imports #21

Open Gregofi opened 2 months ago

Gregofi commented 2 months ago

Currently, imports are done like this:

import { id } from './path';

As of now, it has shortcomings

However, how to solve this? The design of type inference unfortunately does not make this much easy. Transitive imports then plague the namespace of the module (remember, there are no namespaces, so we must be careful with this). Importing the return type could also work, but has same drawbacks as the transitive imports, although on smaller scale.

Maybe import the standard library in its whole by default, that would cut it down a little.

It would be nice if we could at least use the members and methods of the returned value. That would probably be best solution. However, the implementation is not ready for it. It would have to be added on several layers (inference, ast interpreter).

Gregofi commented 2 months ago

We could consider doing

import './list.mjl' as List;

Which would import all identifiers, this would need to be limited by something (pub fn?). The identifiers could either be used as List::Cons, or just Cons. The latter would cause an error in case of multiple existing identifiers with the name.

It would also allow doing things like

import export './option.mjl' as Option;

which would re-export this module for all those that include it transitively.


Should be easier to implement. We just populate the module with all exported functions. In case of List::Cons, find the module List -> ./list.mjl, and take it straight from there.