Open Gregofi opened 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.
Currently, imports are done like this:
As of now, it has shortcomings
fn foo(): A
, if module importsfoo
, it must also importA
, otherwise it can't do anything with the type (if its a enum, it can't match. If its a struct, it can't access its attributes).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).