phobos dependencies

Dmitry Olshansky dmitry.olsh at gmail.com
Sat Dec 21 00:08:35 PST 2013


21-Dec-2013 00:43, Martin Nowak пишет:
> On 12/20/2013 06:27 PM, Andrei Alexandrescu wrote:
>>
>> I had this idea fot a while, and Walter is favorable of it as well -
>> extend "import" for one-shot use. With that feature the example would
>> become:
>>
>>      void topN(alias less = "a < b",
>>              SwapStrategy ss = SwapStrategy.unstable,
>>              Range, RandomGen)(Range r, size_t nth, ref RandomGen rng)
>>          if (isRandomAccessRange!(Range) && hasLength!Range
>>              && import.std.random.isUniformRNG!RandomGen)
>>      { ... }
>>
>> In this case "import" would syntactically be placed at the beginning of
>> a qualified name, meaning "import this module lazily and look up the
>> symbol in it".
>>
>> This would simplify quite a lot of two-liners into one-liners in other
>> places, too.
>
> The fact that template constraints use the module scope is indeed a root
> cause for a lot of module dependencies, so we should tackle this problem
> specifically.
>
> Couldn't static imports be made lazy without breaking any code?
> The above example would read.
>
> static import std.range.
>
> void foo(R)(R range) if (std.range.isForwardRange!R)
> {
> }
>
That has the disadvantage of importing the whole std.range.
I seriously doubt that we'd get anything better then:

 > import std.range.traits;
 >
 > void foo(R)(R range) if (isForwardRange!R)
 > {
        import std.range;
...
 > }

Stays practical w.r.t. cutting down dependencies and no need to uglify 
constraints. They are not that readable already.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list