August 17, 2013
On Saturday, 17 August 2013 at 01:01:10 UTC, Dicebot wrote:
> Currently it is not the case. typeof(tuple(1,2)) is Tuple!(int,int), not TypeTuple!(int, int). But typeof(TypeTuple(1,2)) is TypeTyple!(int, int) :)

Whu?

There is no such type as TypeTuple!(int, int), it is completely aliased away to a builtin tuple.

Also, printing out types is actually rather misleading, as it chooses when to use or not use tuple() in annoying ways e.g. TypeTuple!(int, string) is (int, string) but TypeTuple!(int, 3) is tuple(int, 3)   Either they are both tuples, or neither is.

To the best of my knowledge, there is only this:

1) collections of items, called tuples. They can contain pretty much anything you want, as long it's available at compile-time.
They are ***not types***. If and only if a tuple contains only types, the tuple itself is a type. This is often referred to as a type-tuple. In current D, tuples of all varieties are created by variadic template parameters.*

2) instantiations of type-tuples. These are a collection of runtime values, individually accessible by indexing or foreach iteration. std.typecons.Tuple is a wrapper around one of these providing some extra functionality.

*std.typetuple.TypeTuple only exists to provide convenient syntax for this.
August 17, 2013
On Saturday, 17 August 2013 at 11:43:09 UTC, John Colvin wrote:
> On Saturday, 17 August 2013 at 01:01:10 UTC, Dicebot wrote:
>> Currently it is not the case. typeof(tuple(1,2)) is Tuple!(int,int), not TypeTuple!(int, int). But typeof(TypeTuple(1,2)) is TypeTyple!(int, int) :)
>
> Whu?
>
> There is no such type as TypeTuple!(int, int), it is completely aliased away to a builtin tuple.

Yeah but there is no syntax for them so I am using TypeTuple for unambiguity. pragma(msg) will print (int, int) for it.

> Also, printing out types is actually rather misleading, as it chooses when to use or not use tuple() in annoying ways e.g. TypeTuple!(int, string) is (int, string) but TypeTuple!(int, 3) is tuple(int, 3)   Either they are both tuples, or neither is.

They are two types of built-in tuples - pure type tuples and expression/mixed tuples. typeof expression tuple is type tuple. Those have same syntax but slightly different semantics.

> To the best of my knowledge, there is only this:
>
> 1) collections of items, called tuples. They can contain pretty much anything you want, as long it's available at compile-time.
> They are ***not types***. If and only if a tuple contains only types, the tuple itself is a type. This is often referred to as a type-tuple. In current D, tuples of all varieties are created by variadic template parameters.*

All true but last statement. They are not "created" anywhere, this is simply most convenient way to capture built-in tuple in a form usable by user code.

> 2) instantiations of type-tuples. These are a collection of runtime values, individually accessible by indexing or foreach iteration. std.typecons.Tuple is a wrapper around one of these providing some extra functionality.

As far as I can observe, instantiations of type tuples are expression tuples. And std.typecons.Tuple is completely different beast, it simply a template struct.

See example:

import std.typetuple;
import std.typecons;
import std.stdio;

void main()
{
	alias TT = TypeTuple!(int, string);
	enum ET = TypeTuple!(2, "2");
	TT twoVars; twoVars[0] = 2; twoVars[1] = "2";
	writeln(typeid(typeof(twoVars)));
	writeln(twoVars);
	writeln(typeid(typeof(ET)));
	writeln(ET);
	auto different = tuple(2, "2");
	writeln(typeid(typeof(different)));
	writeln(different);
	writeln(__traits(allMembers, typeof(different)));
}

------------------------

(int,immutable(char)[])
22
(int,immutable(char)[])
22
std.typecons.Tuple!(int, string).Tuple
Tuple!(int, string)(2, "2")
parseSpecsFieldSpecfieldSpecsextractTypeextractNameinjectNamedFieldssliceSpecsexpandSpecisCompatibleTuplesTypesexpand_0_1fieldat__ctoropEqualsopCmpopAssign_workaround4424slicelengthtoString_expand_field_0_expand_field_1

http://dpaste.dzfl.pl/b98d8537
August 17, 2013
On Saturday, 17 August 2013 at 12:37:23 UTC, Dicebot wrote:
> On Saturday, 17 August 2013 at 11:43:09 UTC, John Colvin wrote:
>> On Saturday, 17 August 2013 at 01:01:10 UTC, Dicebot wrote:
>>> Currently it is not the case. typeof(tuple(1,2)) is Tuple!(int,int), not TypeTuple!(int, int). But typeof(TypeTuple(1,2)) is TypeTyple!(int, int) :)
>>
>> Whu?
>>
>> There is no such type as TypeTuple!(int, int), it is completely aliased away to a builtin tuple.
>
> Yeah but there is no syntax for them so I am using TypeTuple for unambiguity. pragma(msg) will print (int, int) for it.

ok, fair enough.

>> Also, printing out types is actually rather misleading, as it chooses when to use or not use tuple() in annoying ways e.g. TypeTuple!(int, string) is (int, string) but TypeTuple!(int, 3) is tuple(int, 3)   Either they are both tuples, or neither is.
>
> They are two types of built-in tuples - pure type tuples and expression/mixed tuples. typeof expression tuple is type tuple. Those have same syntax but slightly different semantics.

Not quite, there are pure type-tuples (can be used as a type), pure expression-tuples (can be assigned to) and mixed tuples. But then there's also aliases...
	int a;
	auto b = TypeTuple!(a);
	b[0] = 3;
	assert(a == 0);  //passes
clearly b is an instantiation of a typetuple (or an expression-tuple, as you point out), but what is actually going on in it's initialisation?

>> To the best of my knowledge, there is only this:
>>
>> 1) collections of items, called tuples. They can contain pretty much anything you want, as long it's available at compile-time.
>> They are ***not types***. If and only if a tuple contains only types, the tuple itself is a type. This is often referred to as a type-tuple. In current D, tuples of all varieties are created by variadic template parameters.*
>
> All true but last statement. They are not "created" anywhere, this is simply most convenient way to capture built-in tuple in a form usable by user code.

That's what i mean by created. I deliberated over what word to use there for quite a while, but perhaps "capture" is better. Either way, you've got some ct stuff and you want to group it together in to a tuple, variadic template parameters is the way to do it.

>> 2) instantiations of type-tuples. These are a collection of runtime values, individually accessible by indexing or foreach iteration. std.typecons.Tuple is a wrapper around one of these providing some extra functionality.
>
> As far as I can observe, instantiations of type tuples are expression tuples.

That's an interesting way of looking at it. I didn't realise one could do this:
	auto ET = TypeTuple!(2, "2");
	ET[0] = 5;   //perfectly fine

> And std.typecons.Tuple is completely different beast, it simply a template struct.

Yes, as I said: It's a wrapper around an instantiation of a type-tuple.



Every time I think I understand this, there's more...
August 17, 2013
On Saturday, 17 August 2013 at 13:55:10 UTC, John Colvin wrote:
>> And std.typecons.Tuple is completely different beast, it simply a template struct.
>
> Yes, as I said: It's a wrapper around an instantiation of a type-tuple.

By that logic every single possible template with variadic parameters is wrapper around instantiation of type tuple. std.typecons.Tuple does not store expression tuple inside so I don't think it is legal to call it a "wrapper". Simply pseudo-anonymous struct with pseudo-anonymous fields.
August 17, 2013
On 08/17/2013 02:37 PM, Dicebot wrote:
>>
>> 1) collections of items, called tuples. They can contain pretty much
>> anything you want, as long it's available at compile-time.
>> They are ***not types***. If and only if a tuple contains only types,
>> the tuple itself is a type. This is often referred to as a type-tuple.
>> In current D, tuples of all varieties are created by variadic template
>> parameters.*
>
> All true but last statement. They are not "created" anywhere, this is
> simply most convenient way to capture built-in tuple in a form usable by
> user code.

Actually, they are created like this:

Foo!(int,"hello",2)
    ^~~~~~~~~~~~~~~


std.typetuple.TypeTuple is the identity "function" on template argument lists.

August 17, 2013
On 08/17/2013 04:04 PM, Dicebot wrote:
> On Saturday, 17 August 2013 at 13:55:10 UTC, John Colvin wrote:
>>> And std.typecons.Tuple is completely different beast, it simply a
>>> template struct.
>>
>> Yes, as I said: It's a wrapper around an instantiation of a type-tuple.
>
> By that logic every single possible template with variadic parameters is
> wrapper around instantiation of type tuple. std.typecons.Tuple does not
> store expression tuple inside so I don't think it is legal to call it a
> "wrapper". Simply pseudo-anonymous struct with pseudo-anonymous fields.

std.typecons.Tuple!(...).field is an "expression tuple".
August 17, 2013
On Saturday, 17 August 2013 at 14:04:21 UTC, Dicebot wrote:
> On Saturday, 17 August 2013 at 13:55:10 UTC, John Colvin wrote:
>>> And std.typecons.Tuple is completely different beast, it simply a template struct.
>>
>> Yes, as I said: It's a wrapper around an instantiation of a type-tuple.
>
> By that logic every single possible template with variadic parameters is wrapper around instantiation of type tuple. std.typecons.Tuple does not store expression tuple inside so I don't think it is legal to call it a "wrapper". Simply pseudo-anonymous struct with pseudo-anonymous fields.

I'm afraid if you look at the implementation of std.typecons.Tuple, it does exactly what you say it doesn't do. The struct-like aspects (e.g. named access) are simulated using aliases.
August 17, 2013
On Saturday, 17 August 2013 at 14:19:06 UTC, John Colvin wrote:
> I'm afraid if you look at the implementation of std.typecons.Tuple, it does exactly what you say it doesn't do. The struct-like aspects (e.g. named access) are simulated using aliases.

Checked once more and I stand corrected. At first glance at implementation I had impression that is exactly the other way around. That makes situation even more fun.
August 17, 2013
http://wiki.dlang.org/The_D_Programming_Language/Seq
August 17, 2013
On Saturday, 17 August 2013 at 15:50:51 UTC, Timon Gehr wrote:
> http://wiki.dlang.org/The_D_Programming_Language/Seq

I added a little bit on multiple return values.
1 2 3 4
Next ›   Last »