July 13, 2015
On 13-Jul-2015 16:15, Jack Applegame wrote:
> On Monday, 13 July 2015 at 12:53:12 UTC, deadalnix wrote:
>> On Monday, 13 July 2015 at 11:36:48 UTC, Jack Applegame wrote:
>>> Yes, that is I intended.
>>> It is a pretty useless example, just for demonstrating the lack of
>>> support polymorphic recursive data types.
>>
>> So the point is that we should add feature to the language to support
>> useless use cases ?
>
> Not all cases are useless. For example, typical functional programming
> patterns like recursive compile-time trees and lists.

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 recursion
		return cast(Nested!(T[])right_;
	}
	@property auto right(U)(Nested!U type){ // empty template to prevent recursion
		right_ =  cast(void*)right_;
	}
	
	// and lastly the constructor should be templated
	this(U)(T l, Nested!(U) r) {
   	 left = l;
   	 right = r;
  	}
}

-- 
Dmitry Olshansky
July 13, 2015
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 recursion
> 		return cast(Nested!(T[])right_;
> 	}
> 	@property auto right(U)(Nested!U type){ // empty template to prevent recursion
> 		right_ =  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.
July 13, 2015
Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5

July 13, 2015
On 13-Jul-2015 19:44, Jack Applegame wrote:
> Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5
>
Good to know ;)

-- 
Dmitry Olshansky
July 15, 2015
On Monday, 13 July 2015 at 12:53:12 UTC, deadalnix wrote:
> On Monday, 13 July 2015 at 11:36:48 UTC, Jack Applegame wrote:
>> Yes, that is I intended.
>> It is a pretty useless example, just for demonstrating the lack of support polymorphic recursive data types.
>
> So the point is that we should add feature to the language to support useless use cases ?

Stop being an asshole! You don't know everything. It's only useless cause your tiny brain doesn't know how to use it properly.

Instead, wake the fuck up and realize there are other people in the world that think/desire things you don't.

Fucking arrogant prick!


July 15, 2015
On Wed, 15 Jul 2015 01:32:22 +0000, Morbid.Obesity wrote:

love you, dear.

1 2
Next ›   Last »