digitalmars.D.learn - Does D support nested Templates aka Higher Kinded Polymorphism?
- sighoya (5/5) Oct 03 2017 Especially, I mean something like
- rikki cattermole (9/15) Oct 03 2017 struct Foo(T) {
- sighoya (6/21) Oct 03 2017 Cool, but it seems that only a nesting of two is allowed, right?
- Jerry (5/30) Oct 03 2017 That is because you have to wrap multiple with ().
- sighoya (13/13) Oct 03 2017 Thanks,
- Adam D. Ruppe (11/13) Oct 03 2017 Bar takes two arguments, but here you are only passing one. Keep
- sighoya (9/9) Oct 03 2017 But when I write this to:
- Daniel Kozak (12/12) Oct 03 2017 writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)()));
- sighoya (23/38) Oct 03 2017 I still get
- Daniel Kozak (3/44) Oct 03 2017 https://run.dlang.io/is/oqbYNb
- sighoya (2/45) Oct 03 2017 Thanks!!!
Especially, I mean something like T<S> foo(S,T)(T<S> i) { ... }
Oct 03 2017
On 03/10/2017 1:05 PM, sighoya wrote:Especially, I mean something like T<S> foo(S,T)(T<S> i) { ... }struct Foo(T) { T value; } T!S foo(S, alias T)(T!S v) { return v; } void main() { import std.stdio; writeln(foo!(int, Foo)(Foo!int(1))); }
Oct 03 2017
On Tuesday, 3 October 2017 at 12:09:04 UTC, rikki cattermole wrote:On 03/10/2017 1:05 PM, sighoya wrote:Cool, but it seems that only a nesting of two is allowed, right? This one gives an error: T!S!R bar(alias T,alias S,R)(T!S!R v) {return v;} Error: multiple ! arguments are not allowedEspecially, I mean something like T<S> foo(S,T)(T<S> i) { ... }struct Foo(T) { T value; } T!S foo(S, alias T)(T!S v) { return v; } void main() { import std.stdio; writeln(foo!(int, Foo)(Foo!int(1))); }
Oct 03 2017
On Tuesday, 3 October 2017 at 12:58:47 UTC, sighoya wrote:On Tuesday, 3 October 2017 at 12:09:04 UTC, rikki cattermole wrote:That is because you have to wrap multiple with (). Use T!(S!R) instead.On 03/10/2017 1:05 PM, sighoya wrote:Cool, but it seems that only a nesting of two is allowed, right? This one gives an error: T!S!R bar(alias T,alias S,R)(T!S!R v) {return v;} Error: multiple ! arguments are not allowedEspecially, I mean something like T<S> foo(S,T)(T<S> i) { ... }struct Foo(T) { T value; } T!S foo(S, alias T)(T!S v) { return v; } void main() { import std.stdio; writeln(foo!(int, Foo)(Foo!int(1))); }
Oct 03 2017
Thanks, How do I construct such a type. I don't get it done right with: struct Foo(T) { T value; } struct Bar (R,S) { R!S fooint; } T!(S!R) bar(alias T,alias S,R)(T!(S!R) v) {return v;} void main() { import std.stdio; writeln(bar!(Bar,Foo,int)(Bar!(Foo!int(1.0)))); }
Oct 03 2017
On Tuesday, 3 October 2017 at 13:31:00 UTC, sighoya wrote:struct Bar (R,S) {T!(S!R) bar(alias T,alias S,R)(T!(S!R) v) {return v;}Bar takes two arguments, but here you are only passing one. Keep in mind that T!(...) is Bar. You called T!(S!(R)) when it was actually written to accept T!(S, R) It might help to forget about the ! and just think of regular functions. Bar(R, S); is the definition but inside you called T(S(R)) when it expected T(S, R)
Oct 03 2017
But when I write this to: writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); it complains by: test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(17): Error: template instance test.bar!(Bar, Foo, int) error instantiating
Oct 03 2017
writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); Dne 3. 10. 2017 3:55 odpoledne napsal u=C5=BEivatel "sighoya via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com>: But when I write this to: writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); it complains by: test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(17): Error: template instance test.bar!(Bar, Foo, int) error instantiating
Oct 03 2017
On Tuesday, 3 October 2017 at 15:30:52 UTC, Daniel Kozak wrote:writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); Dne 3. 10. 2017 3:55 odpoledne napsal uživatel "sighoya via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com>: But when I write this to: writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); it complains by: test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(17): Error: template instance test.bar!(Bar, Foo, int) error instantiatingI still get test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(18): Error: template instance test.bar!(Bar, Foo, int) error instantiating by struct Foo(T) { T value; } struct Bar (R,S) { R!S fooint; } //T!S foo(S, alias T)(T!S v) { return v; } T!(S!R) bar(alias T,alias S,R)(T!(S!R) v) {return v;} void main() { import std.stdio; //writeln(foo!(int, Foo)(Foo!int(1))); //writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); }
Oct 03 2017
https://run.dlang.io/is/oqbYNb On Tue, Oct 3, 2017 at 5:52 PM, sighoya via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:On Tuesday, 3 October 2017 at 15:30:52 UTC, Daniel Kozak wrote:writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); Dne 3. 10. 2017 3:55 odpoledne napsal u=C5=BEivatel "sighoya via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com>: But when I write this to: writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); it complains by: test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(17): Error: template instance test.bar!(Bar, Foo, int) error instantiatingI still get test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(18): Error: template instance test.bar!(Bar, Foo, int) error instantiating by struct Foo(T) { T value; } struct Bar (R,S) { R!S fooint; } //T!S foo(S, alias T)(T!S v) { return v; } T!(S!R) bar(alias T,alias S,R)(T!(S!R) v) {return v;} void main() { import std.stdio; //writeln(foo!(int, Foo)(Foo!int(1))); //writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); }
Oct 03 2017
On Tuesday, 3 October 2017 at 15:52:52 UTC, sighoya wrote:On Tuesday, 3 October 2017 at 15:30:52 UTC, Daniel Kozak wrote:Thanks!!!writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); Dne 3. 10. 2017 3:55 odpoledne napsal uživatel "sighoya via Digitalmars-d-learn" <digitalmars-d-learn puremagic.com>: But when I write this to: writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); it complains by: test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(17): Error: template instance test.bar!(Bar, Foo, int) error instantiatingI still get test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(11): Error: template instance T!(S!int) does not match template declaration Bar(R, S) test.d(18): Error: template instance test.bar!(Bar, Foo, int) error instantiating by struct Foo(T) { T value; } struct Bar (R,S) { R!S fooint; } //T!S foo(S, alias T)(T!S v) { return v; } T!(S!R) bar(alias T,alias S,R)(T!(S!R) v) {return v;} void main() { import std.stdio; //writeln(foo!(int, Foo)(Foo!int(1))); //writeln(bar!(Bar,Foo,int)(Bar!(Foo,int))); writeln(bar!(Bar,Foo,int)(Bar!(Foo,int)())); }
Oct 03 2017