Jump to page: 1 2
Thread overview
Polymorphic recursive class
Jul 13, 2015
Jack Applegame
Jul 13, 2015
thedeemon
Jul 13, 2015
Jack Applegame
Jul 13, 2015
deadalnix
Jul 13, 2015
Jack Applegame
Jul 13, 2015
Dmitry Olshansky
Jul 13, 2015
Jack Applegame
Jul 13, 2015
deadalnix
Jul 13, 2015
Jack Applegame
Jul 13, 2015
deadalnix
Jul 13, 2015
Dmitry Olshansky
Jul 13, 2015
Jack Applegame
Jul 13, 2015
Jack Applegame
Jul 13, 2015
Dmitry Olshansky
Jul 15, 2015
Morbid.Obesity
Jul 15, 2015
ketmar
July 13, 2015
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 yes, I know about Java type erasure and C# run-time instantiation.

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?

July 13, 2015
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 static methods or other stuff.
July 13, 2015
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 doesn't mean the class isn't used: there can be some static methods or other stuff.
Ok, lets instantiate it only when we use some stuff.
July 13, 2015
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 constructor of given class is used?
>>
>> Because if constructor isn't used doesn't mean the class isn't used: there can be some static methods or other stuff.
> Ok, lets instantiate it only when we use some stuff.

Why does the spec needs to be made more complex for some code that you wouldn't be able to use anyway ?

Just use static if and be done with it.
July 13, 2015
On Monday, 13 July 2015 at 09:03:20 UTC, deadalnix wrote:
> Just use static if and be done with it.
How?


July 13, 2015
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,
    right - {
          left - an array of arrays,
          right - {
             left- an array of array of arrays
             right - an so on ... WTF?
          }
    }
}

Or is that what you intended?

-- 
Dmitry Olshansky
July 13, 2015
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 array of array of arrays
>              right - an so on ... WTF?
>           }
>     }
> }

Yes, that is I intended.
It is a pretty useless example, just for demonstrating the lack of support polymorphic recursive data types.

July 13, 2015
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 ?

July 13, 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 ?

Not all cases are useless. For example, typical functional programming patterns like recursive compile-time trees and lists.
July 13, 2015
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.

« First   ‹ Prev
1 2