Re: Polymorphic recursive class

2015-07-15 Thread ketmar via Digitalmars-d
On Wed, 15 Jul 2015 01:32:22 +, Morbid.Obesity wrote: love you, dear. signature.asc Description: PGP signature

Re: Polymorphic recursive class

2015-07-14 Thread Morbid.Obesity via Digitalmars-d
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

Re: Polymorphic recursive class

2015-07-13 Thread deadalnix via Digitalmars-d
On Monday, 13 July 2015 at 08:12:28 UTC, Jack Applegame wrote: On Monday, 13 July 2015 at 08:05:05 UTC, thedeemon wrote: On Monday, 13 July 2015 at 06:31:33 UTC, Jack Applegame wrote: But is there any reason why D can't follow MLton way - instantiate a class type template ONLY when a

Re: Polymorphic recursive class

2015-07-13 Thread Dmitry Olshansky via Digitalmars-d
On 13-Jul-2015 09:31, Jack Applegame wrote: This code doesn't compile, because recursive template expansion. class Nested(A) { A left; Nested!(A[]) right; You might mean Nested!A[] ? Else it looks like making a construct that is: left - an element, right - { left - an array,

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
On Monday, 13 July 2015 at 10:33:17 UTC, Dmitry Olshansky wrote: You might mean Nested!A[] ? No. Else it looks like making a construct that is: left - an element, right - { left - an array, right - { left - an array of arrays, right - { left- an

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
On Monday, 13 July 2015 at 09:03:20 UTC, deadalnix wrote: Just use static if and be done with it. How?

Re: Polymorphic recursive class

2015-07-13 Thread deadalnix via Digitalmars-d
On Monday, 13 July 2015 at 13:15:46 UTC, Jack Applegame wrote: Not all cases are useless. For example, typical functional programming patterns like recursive compile-time trees and lists. Such a construct in pseudo-D would be useful for all to understand.

Re: Polymorphic recursive class

2015-07-13 Thread Dmitry Olshansky via Digitalmars-d
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

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
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

Re: Polymorphic recursive class

2015-07-13 Thread deadalnix via Digitalmars-d
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 ?

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
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

Re: Polymorphic recursive class

2015-07-13 Thread Dmitry Olshansky via Digitalmars-d
On 13-Jul-2015 19:44, Jack Applegame wrote: Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5 Good to know ;) -- Dmitry Olshansky

Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
This code doesn't compile, because recursive template expansion. class Nested(A) { A left; Nested!(A[]) right; this(A l, Nested!(A[]) r) { left = l; right = r; } } void main() { Nested!int nested = new Nested(1, null); } But it successfully compiles in Java an C#. And

Re: Polymorphic recursive class

2015-07-13 Thread thedeemon via Digitalmars-d
On Monday, 13 July 2015 at 06:31:33 UTC, Jack Applegame wrote: But is there any reason why D can't follow MLton way - instantiate a class type template ONLY when a constructor of given class is used? Because if constructor isn't used doesn't mean the class isn't used: there can be some

Re: Polymorphic recursive class

2015-07-13 Thread Jack Applegame via Digitalmars-d
On Monday, 13 July 2015 at 08:05:05 UTC, thedeemon wrote: On Monday, 13 July 2015 at 06:31:33 UTC, Jack Applegame wrote: But is there any reason why D can't follow MLton way - instantiate a class type template ONLY when a constructor of given class is used? Because if constructor isn't used