Re: Algebraic Data Types in D?

2014-08-01 Thread bearophile via Digitalmars-d
Andrei Alexandrescu: I do agree tagged unions should be pushed into the language; they'd help the GC. A more general solution is to add a onGC() optional method that gets called by the GC on collections, and tells it what's inside the union. Bye, bearophile

Re: Algebraic Data Types in D?

2014-08-01 Thread Timon Gehr via Digitalmars-d
On 08/01/2014 03:26 AM, Andrei Alexandrescu wrote: On 7/31/14, 5:35 PM, Timon Gehr wrote: On 07/31/2014 06:23 PM, Andrei Alexandrescu wrote: On 7/31/14, 6:03 AM, w0rp wrote: On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D

Re: Algebraic Data Types in D?

2014-08-01 Thread Andrei Alexandrescu via Digitalmars-d
On 8/1/14, 7:18 AM, Timon Gehr wrote: It might also be possible that this is what is actually wanted: alias Foo = Algebraic!(int,Algebraic!(This[],double)[]); (I.e. This refers to the inner type.) There is always this issue as well: alias ListInt=Algebraic!(Tuple!(),Tuple!(int,ListInt*));

Re: Algebraic Data Types in D?

2014-08-01 Thread Timon Gehr via Digitalmars-d
On 08/01/2014 05:28 PM, Andrei Alexandrescu wrote: On 8/1/14, 7:18 AM, Timon Gehr wrote: It might also be possible that this is what is actually wanted: alias Foo = Algebraic!(int,Algebraic!(This[],double)[]); (I.e. This refers to the inner type.) There is always this issue as well: alias

Algebraic Data Types in D?

2014-07-31 Thread Remo via Digitalmars-d
http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like this to D2 ?

Re: Algebraic Data Types in D?

2014-07-31 Thread w0rp via Digitalmars-d
On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like this to D2 ? There is a library

Re: Algebraic Data Types in D?

2014-07-31 Thread Wyatt via Digitalmars-d
On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like this to D2 ? I think you're looking

Re: Algebraic Data Types in D?

2014-07-31 Thread Sönke Ludwig via Digitalmars-d
Am 31.07.2014 13:42, schrieb Remo: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like this to D2 ? I'm currently in the process of polishing one

Re: Algebraic Data Types in D?

2014-07-31 Thread Justin Whear via Digitalmars-d
On Thu, 31 Jul 2014 11:42:20 +, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like this to D2 ? In addition

Re: Algebraic Data Types in D?

2014-07-31 Thread bearophile via Digitalmars-d
Justin Whear: In addition to the suggestions of Algebraic or Variant elsewhere in this thread, it's trivial to implement your own concrete tagged unions: struct MyTaggedUnion { enum Type { Int, Float, String } Type tag; union { int int_; float float_; string

Re: Algebraic Data Types in D?

2014-07-31 Thread Andrei Alexandrescu via Digitalmars-d
On 7/31/14, 6:03 AM, w0rp wrote: On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible to add something like

Re: Algebraic Data Types in D?

2014-07-31 Thread Remo via Digitalmars-d
On Thursday, 31 July 2014 at 15:03:09 UTC, Justin Whear wrote: On Thu, 31 Jul 2014 11:42:20 +, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you think it would be possible

Re: Algebraic Data Types in D?

2014-07-31 Thread Meta via Digitalmars-d
On Thursday, 31 July 2014 at 20:28:55 UTC, Remo wrote: How to translate this useless Rust code to D, with as least D code as possible ? How be sure that everything will still work as expected if programmer will add White color ? enum Color { Red, Green, Blue,

Re: Algebraic Data Types in D?

2014-07-31 Thread Timon Gehr via Digitalmars-d
On 07/31/2014 06:23 PM, Andrei Alexandrescu wrote: On 7/31/14, 6:03 AM, w0rp wrote: On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum type also called tagged-union. Do you

Re: Algebraic Data Types in D?

2014-07-31 Thread Andrei Alexandrescu via Digitalmars-d
On 7/31/14, 5:35 PM, Timon Gehr wrote: On 07/31/2014 06:23 PM, Andrei Alexandrescu wrote: On 7/31/14, 6:03 AM, w0rp wrote: On Thursday, 31 July 2014 at 11:42:21 UTC, Remo wrote: http://tech.esper.com/2014/07/30/algebraic-data-types/ D already has product type it is struct. But D lacks sum