Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Jerome BENOIT



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message now.


T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}


The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if 
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if (is(typeof(haystack[0] 
!= needle) == bool)) matches more than one template declaration, 
searching_05.d(9):find(TL,TS) if (is(typeof(longer[0..1] == shorter) : bool)) 
and searching_05.d(18):find()

Is partial ordering really supported ?

Jerome





- Jonathan M Davis


Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Timon Gehr

On 01/18/2012 02:32 PM, Jerome BENOIT wrote:



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message now.


T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}


The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and searching_05.d(18):find()

Is partial ordering really supported ?



Yes it is, and your code snippet indeed compiles on my machine. Are you 
maybe using an outdated version of the compiler?







Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Timon Gehr

On 01/18/2012 04:57 PM, Timon Gehr wrote:

On 01/18/2012 02:32 PM, Jerome BENOIT wrote:



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message now.


T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}


The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and
searching_05.d(18):find()

Is partial ordering really supported ?



Yes it is, and your code snippet indeed compiles on my machine. Are you
maybe using an outdated version of the compiler?




Nevermind, I forgot to pass the -unittest switch. It indeed gives that 
error. The reason it still does not compile is that the workaround 
proposed by Jonathan has slightly different semantics than it would have 
if the compiler already supported overloading of functions against 
function templates.


If exactly one of two equally good matched functions is a templated one, 
the other one is chosen. Now that you have templated the second 
function, both are an equally good match and both are templated.


If you change the last signature to
int[] find(TL:int[], TS:int[])(TL longer, TS shorter)

It will compile. However, if TL or TS are user-defined types with an 
alias this of type int[], the semantics are still different. I think 
this bug needs special attention.








Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Jerome BENOIT



On 18/01/12 17:07, Timon Gehr wrote:

On 01/18/2012 04:57 PM, Timon Gehr wrote:

On 01/18/2012 02:32 PM, Jerome BENOIT wrote:



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message now.


T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}


The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and
searching_05.d(18):find()

Is partial ordering really supported ?



Yes it is, and your code snippet indeed compiles on my machine. Are you
maybe using an outdated version of the compiler?




Nevermind, I forgot to pass the -unittest switch. It indeed gives that error. 
The reason it still does not compile is that the workaround proposed by 
Jonathan has slightly different semantics than it would have if the compiler 
already supported overloading of functions against function templates.

If exactly one of two equally good matched functions is a templated one, the 
other one is chosen.


So the D code in my first post may work and thus the workaround is not 
necessary.

For information, I use gdc on a Debian Testing box.

 Now that you have templated the second function, both are an equally good 
match and both are templated.


If you change the last signature to
int[] find(TL:int[], TS:int[])(TL longer, TS shorter)

It will compile. However, if TL or TS are user-defined types with an alias this 
of type int[], the semantics are still different. I think this bug needs 
special attention.







Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Timon Gehr

On 01/18/2012 05:40 PM, Jerome BENOIT wrote:



On 18/01/12 17:07, Timon Gehr wrote:

On 01/18/2012 04:57 PM, Timon Gehr wrote:

On 01/18/2012 02:32 PM, Jerome BENOIT wrote:



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message
now.



T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}



The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and
searching_05.d(18):find()

Is partial ordering really supported ?



Yes it is, and your code snippet indeed compiles on my machine. Are you
maybe using an outdated version of the compiler?




Nevermind, I forgot to pass the -unittest switch. It indeed gives that
error. The reason it still does not compile is that the workaround
proposed by Jonathan has slightly different semantics than it would
have if the compiler already supported overloading of functions
against function templates.

If exactly one of two equally good matched functions is a templated
one, the other one is chosen.


So the D code in my first post may work and thus the workaround is not
necessary.



The language does not mandate the workaround, but the workaround is 
necessary until the compiler is fixed.


Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Jerome BENOIT



On 18/01/12 18:05, Timon Gehr wrote:

On 01/18/2012 05:40 PM, Jerome BENOIT wrote:



On 18/01/12 17:07, Timon Gehr wrote:

On 01/18/2012 04:57 PM, Timon Gehr wrote:

On 01/18/2012 02:32 PM, Jerome BENOIT wrote:



On 18/01/12 04:36, Jonathan M Davis wrote:

On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:

And I cannot figure why :-(


http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its
signature to

int[] find()(int[] longer, int[] shorter)


actually it does not work either: gdmd gives an other error message
now.



T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find()(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
// Test the introduced overloads
long[] a1 = [ 6, 1, 2, 3 ];
long[] a2 = [ 1 , 2 ];
int[] b1 = [ 6, 1, 2, 3 ];
int[] b2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
assert(find(a1, b2) == a1[1 .. $]);
assert(find(b1, b2) == b1[1 .. $]);
}

void main() {}



The message is now:
searching_05.d:34: Error: template searching_05.find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) find(T,E) if
(is(typeof(haystack[0] != needle) == bool)) matches more than one
template declaration, searching_05.d(9):find(TL,TS) if
(is(typeof(longer[0..1] == shorter) : bool)) and
searching_05.d(18):find()

Is partial ordering really supported ?



Yes it is, and your code snippet indeed compiles on my machine. Are you
maybe using an outdated version of the compiler?




Nevermind, I forgot to pass the -unittest switch. It indeed gives that
error. The reason it still does not compile is that the workaround
proposed by Jonathan has slightly different semantics than it would
have if the compiler already supported overloading of functions
against function templates.

If exactly one of two equally good matched functions is a templated
one, the other one is chosen.


So the D code in my first post may work and thus the workaround is not
necessary.



The language does not mandate the workaround, but the workaround is necessary 
until the compiler is fixed.


Thanks for the precision. So I will move to the next section and come back to 
this part when the compiler is fix:
I guess it will be fixed for the next release as it sounds as an important bug.

Jerome



Re: tdpl: partial ordering of functions: conflict error

2012-01-18 Thread Jonathan M Davis
On Wednesday, January 18, 2012 21:35:44 Jerome BENOIT wrote:
 Thanks for the precision. So I will move to the next section and come back
 to this part when the compiler is fix: I guess it will be fixed for the
 next release as it sounds as an important bug.

I don't know. It's been a bug for a long time. However, there has been push 
recently to try and get the known bugs with regards to TDPL fixed, and this is 
definitely on the list. So, I would expect it to be fixed relatively soon, but 
it may not be fixed by the next release.

- Jonathan M Davis


tdpl: partial ordering of functions: conflict error

2012-01-17 Thread Jerome BENOIT

Hello List:

On my box, the following D source, inspired by the subsection 5.5.2 of tDpl, 
arises a `template conflict':

-

T[] find(T, E)(T[] haystack, E needle)
if (is(typeof(haystack[0] != needle) == bool)) {
while (haystack.length  0  haystack[0] != needle) {
haystack = haystack[1 .. $];
}
return haystack;
}

TL[] find(TL, TS)(TL[] longer, TS[] shorter)
if (is(typeof(longer[0 .. 1] == shorter) : bool)) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

int[] find(int[] longer, int[] shorter) {
while (longer.length = shorter.length) {
if (longer[0 .. shorter.length] == shorter) break;
longer=longer[1 .. $];
}
return longer;
}

unittest {
long[] a1 = [ 6, 1, 2, 3 ];
int[] a2 = [ 1 , 2 ];
assert(find(a1, a2) == a1[1 .. $]);
}

void main() {}

-

And I cannot figure why :-(

Thanks in advance for any help,
Jerome


Re: tdpl: partial ordering of functions: conflict error

2012-01-17 Thread Jonathan M Davis
On Wednesday, January 18, 2012 02:33:25 Jerome BENOIT wrote:
 And I cannot figure why :-(

http://d.puremagic.com/issues/show_bug.cgi?id=1528

As a workaround, templatize the last function by changing its signature to

int[] find()(int[] longer, int[] shorter)

- Jonathan M Davis