Does D support nested Templates aka Higher Kinded Polymorphism?

sighoya sighoya at gmail.com
Tue Oct 3 15:52:52 UTC 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 at 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

I 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)()));
}




More information about the Digitalmars-d-learn mailing list