On Monday, 13 July 2015 at 13:51:51 UTC, Dmitry Olshansky wrote:
You can do it no problem, it just requires to manually implement boxing and make `right` a template that casts to the right type. The reason is that D doesn't provide an extra abstraction layer that is "auto-magically" there in typical FP language.Not tested but this should work: class Nested(T){ T left; void* right_; // or use opaque type if allergic to void*@property auto right()(){ // empty template to prevent recursionreturn cast(Nested!(T[])right_; }@property auto right(U)(Nested!U type){ // empty template to prevent recursionright_ = cast(void*)right_; } // and lastly the constructor should be templated this(U)(T l, Nested!(U) r) { left = l; right = r; } }
Wow! Template properties is nice idea. Thanks.
