Jump to page: 1 2 3
Thread overview
Shameless autopromotion : type safe tagged union in D
May 10, 2013
deadalnix
May 10, 2013
John Colvin
May 10, 2013
John Colvin
May 10, 2013
deadalnix
May 10, 2013
deadalnix
May 10, 2013
Walter Bright
May 10, 2013
Jesse Phillips
May 12, 2013
SomeDude
May 10, 2013
John Colvin
May 10, 2013
deadalnix
May 10, 2013
Dmitry Olshansky
May 10, 2013
deadalnix
May 10, 2013
John Colvin
May 10, 2013
Artur Skawina
May 10, 2013
deadalnix
May 10, 2013
Piotr Szturmaj
May 10, 2013
Timon Gehr
May 16, 2013
Nick Sabalausky
May 17, 2013
deadalnix
May 10, 2013
http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/

A trick that I used to use more and more, so I ended up creating a generic solution and wrote an article about it.
May 10, 2013
On Friday, 10 May 2013 at 12:32:50 UTC, deadalnix wrote:
> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>
> A trick that I used to use more and more, so I ended up creating a generic solution and wrote an article about it.

Fancy some proof-reading again?
May 10, 2013
On Friday, 10 May 2013 at 12:47:17 UTC, John Colvin wrote:
> On Friday, 10 May 2013 at 12:32:50 UTC, deadalnix wrote:
>> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>>
>> A trick that I used to use more and more, so I ended up creating a generic solution and wrote an article about it.
>
> Fancy some proof-reading again?

I went ahead and did a brief pass over it as I read it: http://db.tt/DqRbEO5u

Nice article. This is the sort of thing that D really excels at compared to C++.

Is this on Reddit yet?
May 10, 2013
10-May-2013 16:32, deadalnix пишет:
> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>
>
> A trick that I used to use more and more, so I ended up creating a
> generic solution and wrote an article about it.

Neat but somewhat limited.

E.g. this is exactly the same switch madness we sought to avoid:

void process(T)(T data) {
    alias Type = typeof(data);

    static if(is(Type == A)) {
        // Code that handle the case where it is an A.
    } else static if(is(Type == B)) {
        // Code that handle the case where it is an B.
    } else {
        static assert(0, "You must handle type " ~ Type.stringof);
    }
}

t.apply!process();


I'd rather see another idiom supported too:

t.apply!(processA, processB)();

where e.g.
void proccessA(A value){ ... }

void processB(B value){ ... }

Anther thing is that will allow succinct notations like:

int squared = t.apply!(
	(A a) => a.x*a.x + a.y*a.y,
	(B b) => b.x*b.x + b.y*b.y + b.z*b.z
)();

I sure don't fancy putting static if into lambdas.
Another thing about it is it allows specifying safe catch all or default case.


-- 
Dmitry Olshansky
May 10, 2013
On Friday, 10 May 2013 at 13:04:58 UTC, John Colvin wrote:
> On Friday, 10 May 2013 at 12:47:17 UTC, John Colvin wrote:
>> On Friday, 10 May 2013 at 12:32:50 UTC, deadalnix wrote:
>>> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>>>
>>> A trick that I used to use more and more, so I ended up creating a generic solution and wrote an article about it.
>>
>> Fancy some proof-reading again?
>
> I went ahead and did a brief pass over it as I read it: http://db.tt/DqRbEO5u
>

Awesome, I'll update the article.

> Nice article. This is the sort of thing that D really excels at compared to C++.
>
> Is this on Reddit yet?

No, feel free to put it if you think it is appropriate !
May 10, 2013
On Friday, 10 May 2013 at 13:11:37 UTC, Dmitry Olshansky wrote:
> E.g. this is exactly the same switch madness we sought to avoid:
>

The article don't plan to avoid this, but to make the tagged union safe. I agree this is a plus, but didn't really took time to make that work.

> void process(T)(T data) {
>     alias Type = typeof(data);
>
>     static if(is(Type == A)) {
>         // Code that handle the case where it is an A.
>     } else static if(is(Type == B)) {
>         // Code that handle the case where it is an B.
>     } else {
>         static assert(0, "You must handle type " ~ Type.stringof);
>     }
> }
>
> t.apply!process();
>
>
> I'd rather see another idiom supported too:
>
> t.apply!(processA, processB)();
>
> where e.g.
> void proccessA(A value){ ... }
>
> void processB(B value){ ... }
>

That can work indeed.

> Anther thing is that will allow succinct notations like:
>
> int squared = t.apply!(
> 	(A a) => a.x*a.x + a.y*a.y,
> 	(B b) => b.x*b.x + b.y*b.y + b.z*b.z
> )();
>
> I sure don't fancy putting static if into lambdas.
> Another thing about it is it allows specifying safe catch all or default case.

That last one won't work. DMD don't accept locals here, even if they are functions.
May 10, 2013
On Friday, 10 May 2013 at 13:51:11 UTC, deadalnix wrote:
>> Is this on Reddit yet?
>
> No, feel free to put it if you think it is appropriate !

http://www.reddit.com/r/programming/comments/1e2h99/type_safe_tagged_union_in_d/

Someone else did.
May 10, 2013
On 5/10/13 8:32 AM, deadalnix wrote:
> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>
>
> A trick that I used to use more and more, so I ended up creating a
> generic solution and wrote an article about it.

Article is good, could use a few copyediting fixes (including in title). Any volunteers?

Andrei
May 10, 2013
On Friday, 10 May 2013 at 14:37:49 UTC, Andrei Alexandrescu wrote:
> On 5/10/13 8:32 AM, deadalnix wrote:
>> http://www.deadalnix.me/2013/05/10/type-safe-tagged-union-in-d-programming-language/
>>
>>
>> A trick that I used to use more and more, so I ended up creating a
>> generic solution and wrote an article about it.
>
> Article is good, could use a few copyediting fixes (including in title). Any volunteers?
>
> Andrei

Done (except the title)
http://forum.dlang.org/post/dszacipmkljzjybcojzm@forum.dlang.org
May 10, 2013
On Friday, 10 May 2013 at 13:51:11 UTC, deadalnix wrote:
>
> Awesome, I'll update the article.
>

Andrei pointed out that the title needed fixing:

I suggest:
Type-safe tagged unions in the D programming language.
Type-safe tagged unions in D.
« First   ‹ Prev
1 2 3