phobos dependencies

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Dec 20 11:29:13 PST 2013


On Fri, Dec 20, 2013 at 01:17:29PM -0600, captaindet wrote:
> On 2013-12-20 11:38, H. S. Teoh wrote:
[...]
> >Hmm. Why do we need to incorporate the 'import' keyword in the first
> >place? What about extending symbol lookup, so that if a
> >fully-qualified symbol x.y.z can't be found in the current symbol
> >tables, and x/y exists in the current import path, then implicitly
> >try to import x.y and lookup z in that module. Then you could just
> >write:
> >
> >	void f(T)(T t) if (std.range.isInputRange!T) ...
> >
> >and the compiler will automatically import std.range within that
> >scope.  Obviously, it's a bad idea to import std.range into module
> >scope, since it would pollute the module namespace, but it seems a
> >good idea to do a one-shot import automatically, since the qualified
> >symbol itself already says which module the symbol is supposed to be
> >defined in. There's no need to add another "import." prefix to it,
> >IMO.
> >
> >
> >T
> 
> one could make it a bit more explicit by requiring
> 
> 	import std;
> 
> at module level, or even more explicit
> 
> 	auto import std;
> 
> to enable lazy import of everything that is hierarchically below.
> could then be used for user libraries as well:
[...]

I like this idea. It could also be denoted as 'lazy import std', that
is, if something references 'std.xyz.abc', then import the module
std.xyz and lookup the symbol 'abc'. Then you could just use
std.range.isInputRange in your signature constraints, and the import
will only happen if you actually instantiate that template.

A more restricted variant, which may be more palatable to Walter, is to
require explicit modules, i.e., you can't just say 'lazy import std',
but you have to say 'lazy import std.range':

	lazy import std.range;

	void func(T)(T t)
		if (std.range.isInputRange!T)
	{
		...
	}

So the compiler at least knows that 'std.range' refers to some as-yet
unimported module, then when you actually reference a symbol under
std.range, the compiler will go and import the module to find its
definition.


T

-- 
IBM = I'll Buy Microsoft!


More information about the Digitalmars-d mailing list