Thread overview | |||||
---|---|---|---|---|---|
|
January 25, 2004 Consider Generic/Template Modules | ||||
---|---|---|---|---|
| ||||
For example: module A (T, alias M : module) { private import M; class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, this); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes. In other words, one can configure a module with the symbols from another. I'm not sure how complicated this feature is to implement -- is it as bad as general support for ADL. One could view it as a mechanism for selective ADL. I believe they call it higher-order functors in some languages like SML. Matthias |
January 27, 2004 Re: Consider Generic/Template Modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthias Spycher | You can do this now: module A (T, alias M) { class Boxed{ T val; ... } Boxed f() { T x = M.g(); // we expect module M to provide g() for type T return Boxed(x); } } --- module B; private import A!(int, B); static count = 0; function int g() { return ++count; } Boxed!(int) y = f!(); --- "Matthias Spycher" <matthias@coware.com> wrote in message news:bv0po5$2ro4$1@digitaldaemon.com... > For example: > > module A (T, alias M : module) { > private import M; > > class Boxed{ > T val; > ... > } > > Boxed f() { > T x = M.g(); // we expect module M to provide g() for type T > return Boxed(x); > } > > } > > --- > > module B; > private import A!(int, this); > > static count = 0; > function int g() { > return ++count; > } > > Boxed!(int) y = f!(); > > --- > > One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes. In other words, one can configure a module with the symbols from another. > > I'm not sure how complicated this feature is to implement -- is it as bad as > general support for ADL. One could view it as a mechanism for selective ADL. > I believe they call it higher-order functors in some languages like SML. > > Matthias > > |
January 27, 2004 Re: Consider Generic/Template Modules | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Very cool indeed! I was thinking about a module configuration pattern that would allow us to do AspectD using generic modules, but I have to give it some more thought... Cheers Matthias "Walter" <walter@digitalmars.com> wrote in message news:bv4cev$2khv$1@digitaldaemon.com... > You can do this now: > > module A (T, alias M) { > class Boxed{ > T val; > ... > } > > Boxed f() { > T x = M.g(); // we expect module M to provide g() for type T > return Boxed(x); > } > > } > > --- > > module B; > private import A!(int, B); > > static count = 0; > function int g() { > return ++count; > } > > Boxed!(int) y = f!(); > > --- > > > "Matthias Spycher" <matthias@coware.com> wrote in message news:bv0po5$2ro4$1@digitaldaemon.com... > > For example: > > > > module A (T, alias M : module) { > > private import M; > > > > class Boxed{ > > T val; > > ... > > } > > > > Boxed f() { > > T x = M.g(); // we expect module M to provide g() for type T > > return Boxed(x); > > } > > > > } > > > > --- > > > > module B; > > private import A!(int, this); > > > > static count = 0; > > function int g() { > > return ++count; > > } > > > > Boxed!(int) y = f!(); > > > > --- > > > > One could basically inject the symbols of a module into another during import and then resolve template members in the context of both scopes. In > > other words, one can configure a module with the symbols from another. > > > > I'm not sure how complicated this feature is to implement -- is it as bad > as > > general support for ADL. One could view it as a mechanism for selective > ADL. > > I believe they call it higher-order functors in some languages like SML. > > > > Matthias > > > > > > |
Copyright © 1999-2021 by the D Language Foundation