Re: Const Tuples

2014-04-25 Thread Dicebot via Digitalmars-d-learn
On Friday, 25 April 2014 at 11:51:48 UTC, bearophile wrote: They are not the same type: void main() { import std.typecons: Tuple; alias T1 = const Tuple!(int, int); alias T2 = Tuple!(const int, const int); static assert(is(T1 == T2)); // Fails. } This type difference causes

Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
They are not the same type: void main() { import std.typecons: Tuple; alias T1 = const Tuple!(int, int); alias T2 = Tuple!(const int, const int); static assert(is(T1 == T2)); // Fails. } This type difference causes some troubles when you use tuples. Bye, bearophile

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Dicebot: Why would you even expect those to be same types? These 2 types are also different: struct A { const int x; } alias A_ = const(A); In general a tuple is a higher level data structure compared to a struct. So it's not unreasonable to expect a Tuple to be more flexible than a

Re: Const Tuples

2014-04-25 Thread Dicebot via Digitalmars-d-learn
On Friday, 25 April 2014 at 12:17:31 UTC, bearophile wrote: In general a tuple is a higher level data structure compared to a struct. So it's not unreasonable to expect a Tuple to be more flexible than a struct. Well, wrong :) std.typecons.Tuple IS a struct -

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Dicebot: Well, wrong :) std.typecons.Tuple IS a struct - https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L388 Nope, that's just an implementation detail. They are two quite different data structures. Example: slicing a tuple always has a meaning, while slicing a

Re: Const Tuples

2014-04-25 Thread Dicebot via Digitalmars-d-learn
On Friday, 25 April 2014 at 12:42:33 UTC, bearophile wrote: Dicebot: Well, wrong :) std.typecons.Tuple IS a struct - https://github.com/D-Programming-Language/phobos/blob/master/std/typecons.d#L388 Nope, that's just an implementation detail. They are two quite different data structures.

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Dicebot: std.typecons.Tuple is just a subset of all structs implementing specific behavior. It still acts as struct everywhere when applicable. A subset is not the same as the whole set. You are missing something important about what a data structure is. Take a look at your computer

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
I was just expressing a little frustration :-) An example; despite it looks simple I am missing something: import std.typecons: Tuple, tuple; import std.algorithm: reduce; struct Foo { int x; } auto foo(in Tuple!(Foo[]) arg, int) { return tuple(arg[0]); } void main() { int[] data;

Re: Const Tuples

2014-04-25 Thread Dicebot via Digitalmars-d-learn
On Friday, 25 April 2014 at 12:54:25 UTC, bearophile wrote: Dicebot: std.typecons.Tuple is just a subset of all structs implementing specific behavior. It still acts as struct everywhere when applicable. A subset is not the same as the whole set. You are missing something important about

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Dicebot: It would be weird exception of general type system rules with no practical justification I can readily imagine. I partially disagree. It could be useful to have structural typing (http://en.wikipedia.org/wiki/Structural_type_system ) only on tuples (and not on structs), because the

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
import std.typecons: Tuple, tuple; import std.algorithm: reduce; struct Foo { int x; } auto foo(in Tuple!(Foo[]) arg, int) { return tuple(arg[0]); } void main() { int[] data; Foo[] empty; auto seed = tuple(empty); reduce!foo(seed, data); } I have found a solution: import

Re: Const Tuples

2014-04-25 Thread Meta via Digitalmars-d-learn
On Friday, 25 April 2014 at 11:51:48 UTC, bearophile wrote: They are not the same type: void main() { import std.typecons: Tuple; alias T1 = const Tuple!(int, int); alias T2 = Tuple!(const int, const int); static assert(is(T1 == T2)); // Fails. } This type difference causes

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Meta: I think it's a bad idea to make these equal for this reason: if T1 == T2, then you would expect Unqual!T1 == Unqual!T2. However: alias T1 = const Tuple!(int, int); alias T2 = Tuple!(const int, const int); assert(is(T1 == T2)); alias UnT1 = Unqual!T1; // Tuple!(int, int) alias UnT2 =

Re: Const Tuples

2014-04-25 Thread Dicebot via Digitalmars-d-learn
On Friday, 25 April 2014 at 13:18:13 UTC, bearophile wrote: Dicebot: It would be weird exception of general type system rules with no practical justification I can readily imagine. I partially disagree. It could be useful to have structural typing

Re: Const Tuples

2014-04-25 Thread bearophile via Digitalmars-d-learn
Dicebot: For your objections to make sense tuple would need to be inroduced as completely new first class type system entity. As this will never happen, I think first class tuples will happen in D, because the current tuple situation is quite bad. But this thread is not about built-in