digitalmars.D - Polymorphic recursive class
- Jack Applegame (17/17) Jul 12 2015 This code doesn't compile, because recursive template expansion.
- thedeemon (3/6) Jul 13 2015 Because if constructor isn't used doesn't mean the class isn't
- Jack Applegame (2/8) Jul 13 2015 Ok, lets instantiate it only when we use some stuff.
- deadalnix (4/14) Jul 13 2015 Why does the spec needs to be made more complex for some code
- Jack Applegame (2/3) Jul 13 2015 How?
- Dmitry Olshansky (17/21) Jul 13 2015 You might mean Nested!A[] ?
- Jack Applegame (5/18) Jul 13 2015 Yes, that is I intended.
- deadalnix (3/6) Jul 13 2015 So the point is that we should add feature to the language to
- Jack Applegame (3/9) Jul 13 2015 Not all cases are useless. For example, typical functional
- deadalnix (3/6) Jul 13 2015 Such a construct in pseudo-D would be useful for all to
- Dmitry Olshansky (25/35) Jul 13 2015 You can do it no problem, it just requires to manually implement boxing
- Jack Applegame (2/26) Jul 13 2015 Wow! Template properties is nice idea. Thanks.
- Jack Applegame (1/1) Jul 13 2015 Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5
- Dmitry Olshansky (4/5) Jul 13 2015 Good to know ;)
- Morbid.Obesity (6/12) Jul 14 2015 Stop being an asshole! You don't know everything. It's only
- ketmar (2/2) Jul 15 2015 On Wed, 15 Jul 2015 01:32:22 +0000, Morbid.Obesity wrote:
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 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?
Jul 12 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.
Jul 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:Ok, lets instantiate it only when we use some stuff.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.
Jul 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: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.On Monday, 13 July 2015 at 06:31:33 UTC, Jack Applegame wrote:Ok, lets instantiate it only when we use some stuff.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.
Jul 13 2015
On Monday, 13 July 2015 at 09:03:20 UTC, deadalnix wrote:Just use static if and be done with it.How?
Jul 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
Jul 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.
Jul 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 ?
Jul 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:Not all cases are useless. For example, typical functional programming patterns like recursive compile-time trees and lists.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 ?
Jul 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.
Jul 13 2015
On 13-Jul-2015 16:15, Jack Applegame wrote:On Monday, 13 July 2015 at 12:53:12 UTC, deadalnix 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; } } -- Dmitry OlshanskyOn Monday, 13 July 2015 at 11:36:48 UTC, Jack Applegame wrote:Not all cases are useless. For example, typical functional programming patterns like recursive compile-time trees and lists.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 ?
Jul 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.
Jul 13 2015
Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5
Jul 13 2015
On 13-Jul-2015 19:44, Jack Applegame wrote:Yes! It works: http://dpaste.dzfl.pl/b9c6a2a958e5Good to know ;) -- Dmitry Olshansky
Jul 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: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!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 ?
Jul 14 2015
On Wed, 15 Jul 2015 01:32:22 +0000, Morbid.Obesity wrote: love you, dear.=
Jul 15 2015