Re: UFCS with constructors

2013-11-07 Thread bearophile
qznc: Operator precedence of . is higher than unary minus. You are right, I didn't know it, so Typedef and constructors are not to blame: double foo(in double x) { assert (x = 0); return x; } void main() { assert(-1.foo == -1); } Is this a good design of the operator

UFCS with constructors

2013-11-06 Thread bearophile
import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3)); auto a4 = -1.Foo; pragma(msg, typeof(a4)); } It prints:

Re: UFCS with constructors

2013-11-06 Thread qznc
On Wednesday, 6 November 2013 at 11:04:05 UTC, bearophile wrote: import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3));

Re: UFCS with constructors

2013-11-06 Thread bearophile
qznc: Operator precedence of . is higher than unary minus. Is this good? However, what is Typedef for? It's to create a differently named type, useful for stronger static typing, to increase code clarity and avoid some bugs. If you have a function like this: double foo(in double x,

Re: UFCS with constructors

2013-11-06 Thread Ali Çehreli
On 11/06/2013 03:04 AM, bearophile wrote: import std.typecons: Typedef; alias Foo = Typedef!double; void main() { auto a1 = Foo(1); pragma(msg, typeof(a1)); auto a2 = 1.Foo; pragma(msg, typeof(a2)); auto a3 = Foo(-1); pragma(msg, typeof(a3)); auto a4 = -1.Foo;

Re: UFCS with constructors

2013-11-06 Thread Maxim Fomin
On Wednesday, 6 November 2013 at 17:10:34 UTC, Ali Çehreli wrote: I would be very surprised if unary - produced a different type from the operand: Ali Operator does not produce type, it produces value of expression, and type of expression happens not to be the type you expected. But such

Re: UFCS with constructors

2013-11-06 Thread Ali Çehreli
On 11/06/2013 09:46 AM, Maxim Fomin wrote: On Wednesday, 6 November 2013 at 17:10:34 UTC, Ali Çehreli wrote: I would be very surprised if unary - produced a different type from the operand: Ali Operator does not produce type, it produces value of expression, and type of expression

Re: UFCS with constructors

2013-11-06 Thread Maxim Fomin
On Wednesday, 6 November 2013 at 18:02:32 UTC, Ali Çehreli wrote: But such expectations need not correspond to language rules (try to think from from language laywer perspective). I still argue that the expression -expr must have the same type as expr. In bearophile case, I guess

Re: UFCS with constructors

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 18:16:04 UTC, Maxim Fomin wrote: I think that reason for such behavior is the way used defined operator overloading functions are implemented, not the language per se, so programmers confuse themselves. What about other possible reason - Typedef implementation

Re: UFCS with constructors

2013-11-06 Thread bearophile
Dicebot: Typedef implementation sucks? ;) So do you suggest to open some enhancement request/bug report on Typedef? Bye, bearophile

Re: UFCS with constructors

2013-11-06 Thread Dicebot
On Wednesday, 6 November 2013 at 21:57:47 UTC, bearophile wrote: Dicebot: Typedef implementation sucks? ;) So do you suggest to open some enhancement request/bug report on Typedef? Bye, bearophile Sure. get enough such reports and we may even get it back as language feature :) (I think