Re: PROPOSAL: Implicit conversions of integer literals to floating

2011-01-01 Thread so
I'd be in favor of that. Can't see it break stuff in anything but good ways. I am not sure if it is that good. Say you want to make a generic vector class that accepts both integer and float values. This might seem trivial, well it is but it gets very ugly. You are going to need cast on each

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-31 Thread Max Samukha
On 12/31/2010 04:47 AM, Andrej Mitrovic wrote: On 12/31/10, Manfred_Nowak wrote: Andrej Mitrovic wrote: "Overload sets can be merged with an alias declaration" [...] That's not the point. The point is it works with a long variable, but not with a long literal. ??? According to the specs

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-31 Thread Max Samukha
On 12/31/2010 02:44 AM, Walter Bright wrote: Andrei Alexandrescu wrote: I agree there's an issue here, but not only with floating point numbers: void fun(long); void fun(ulong); ... fun(2); // whaa? That's a feature, not a bug. void foo(string s); void foo(wstring s); foo("whoa"); This fa

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread bearophile
Don: > Personally, I'd love to see implicit conversions int<->floating point > completely removed from the language. But I think there'd be an outcry > if that happened. It's a significant change. How much work does it need to create a complied side branch of DMD 2.051 with this difference? Wi

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Andrej Mitrovic
On 12/31/10, Manfred_Nowak wrote: > Andrej Mitrovic wrote: > >> > "Overload sets can be merged with an alias declaration" > [...] >> That's not the point. The point is it works with a long variable, but >> not with a long literal. > > ??? > > According to the specs it shoudn't compile in both case

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Manfred_Nowak
Andrej Mitrovic wrote: > > "Overload sets can be merged with an alias declaration" [...] > That's not the point. The point is it works with a long variable, but > not with a long literal. ??? According to the specs it shoudn't compile in both cases. -manfred

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread spir
On Thu, 30 Dec 2010 14:34:45 -0600 Andrei Alexandrescu wrote: > >> Then people probably need to use sqrt(2.0) or sqrt(cast(double)2). > > > > I've got a lot of sympathy for the first alternative (absolutely NONE > > for the second!). But unfortunately, the language allows sqrt(2) to > > compile

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread spir
On Thu, 30 Dec 2010 21:13:05 +0100 Don wrote: > Yes, but OCaML isn't a C-family language, inheriting C's broken > treatment of literals. Just for information (I really mean information, not starting a new discussion): was it proposed to let down such legacy mess form C at the time when D1-->D

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Manfred_Nowak
Don wrote: > disallow conversions integer->floating point In version 0.80 floating point->integer was disallowed. The reasons that triggered that disallowance in 0.80 are symmetric. A reason was: `(4,2)' might be mistyped as `(4.2)' and symmetric means: `(4.2)' might be mistyped as `(4,2)

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread Walter Bright
Andrei Alexandrescu wrote: I agree there's an issue here, but not only with floating point numbers: void fun(long); void fun(ulong); ... fun(2); // whaa? That's a feature, not a bug.

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread Simen kjaeraas
Don wrote: Personally, I'd love to see implicit conversions int<->floating point completely removed from the language. But I think there'd be an outcry if that happened. I'd be in favor of that. Can't see it break stuff in anything but good ways. -- Simen

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Andrej Mitrovic
On 12/31/10, Manfred_Nowak wrote: > Andrej Mitrovic wrote: > >> bug with [...] cross-module overloading > > "Overload sets can be merged with an alias declaration" > http://www.digitalmars.com/d/2.0/function.html (cited 12/31/10) > > -manfred > That's not the point. The point is it works with a l

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Manfred_Nowak
Andrej Mitrovic wrote: > bug with [...] cross-module overloading "Overload sets can be merged with an alias declaration" http://www.digitalmars.com/d/2.0/function.html (cited 12/31/10) -manfred

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Andrej Mitrovic
FYI, there is a bug with long literals and cross-module overloading. But I've managed to screw up the first report over 4 months ago and just noticed it now (sorry!). The revised report is in the second comment: http://d.puremagic.com/issues/show_bug.cgi?id=4702#c1

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread so
But people don't expect 1/2 to return 0.5000 and D isn't C++ There are languages that have had to wait for a major language update to reach that: http://ideone.com/YdFbl I am not familiar with Python and its community, but such a change in a language even in a major update... great work!

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread Andrei Alexandrescu
On 12/30/10 2:13 PM, Don wrote: bearophile wrote: Don: No. People expect sqrt(2) to compile, and to return 1.414 Then people probably need to use sqrt(2.0) or sqrt(cast(double)2). I've got a lot of sympathy for the first alternative (absolutely NONE for the second!). But unfortunately,

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Don
spir wrote: On Thu, 30 Dec 2010 07:46:19 +0100 Don wrote: This problem has already hit Phobos. We inserted a hack so that sqrt(2) will work. But exp(1) doesn't work. Note that the problems really arise because we've inherited C's rather cavalier approach to implicit conversion. I'm unsure o

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Don
so wrote: This problem has already hit Phobos. We inserted a hack so that sqrt(2) will work. But exp(1) doesn't work. Note that the problems really arise because we've inherited C's rather cavalier approach to implicit conversion. Classifying 2 as an int was a very wrong start. Exactly. It's

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread Don
bearophile wrote: Don: No. People expect sqrt(2) to compile, and to return 1.414 Then people probably need to use sqrt(2.0) or sqrt(cast(double)2). I've got a lot of sympathy for the first alternative (absolutely NONE for the second!). But unfortunately, the language allows sqrt(2) to

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread bearophile
Alex_Dovhal: > But people don't expect 1/2 to return 0.5000 and D isn't C++ There are languages that have had to wait for a major language update to reach that: http://ideone.com/YdFbl While other ones have gotten it right from the beginning (Scheme numerical tower is well designed): http://i

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread so
But people don't expect 1/2 to return 0.5000 and D isn't C++ People don't expect it because of the existence of a rule that makes no sense. I would absolutely expect 1/2 to return 0.5! -- Using Opera's revolutionary email client: http://www.opera.com/mail/

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Alex_Dovhal
"Don" wrote: >> Because the coder could have typed `0.0' instead of `0', the coder >> probably wanted the compile time error you described. > > No. People expect sqrt(2) to compile, and to return 1.414 > For example, it works in C and in C++. > > The only other possible solution would be to d

Re: PROPOSAL: Implicit conversions of integer literals to floating

2010-12-30 Thread bearophile
Don: > No. People expect sqrt(2) to compile, and to return 1.414 Then people probably need to use sqrt(2.0) or sqrt(cast(double)2). > For example, it works in C and in C++. And maybe it doesn't work in OCaML. Bye, bearophile

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread so
This problem has already hit Phobos. We inserted a hack so that sqrt(2) will work. But exp(1) doesn't work. Note that the problems really arise because we've inherited C's rather cavalier approach to implicit conversion. Classifying 2 as an int was a very wrong start. This proposal reminds me

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Don
Manfred_Nowak wrote: Don wrote: 0 converts to double using implicit conversions. The coder should know this while typing. The coder should know about the possible problems while typing. Because the coder could have typed `0.0' instead of `0', the coder probably wanted the compile time error

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Tomek Sowiński
Tomek Sowiński wrote: > I'd cautiously say it is a reasonable proposal not to bother > application > programmers with minutiae of library evolution. My concern is that > instead, programmers would have to be familiar with minutiae of D > literals to understand overload resolution. Another concer

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Manfred_Nowak
Don wrote: > 0 converts to double using implicit conversions. The coder should know this while typing. The coder should know about the possible problems while typing. Because the coder could have typed `0.0' instead of `0', the coder probably wanted the compile time error you described. Theref

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread Tomek Sowiński
Don wrote: > BACKGROUND: > D currently uses a very simple rule for parameter matching: > * it matches exactly; OR > * it matches using implicit conversions; OR > * it does not match. > > There's an important extra feature: polysemous literals (those which > can be interpreted in multiple ways) ha

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-30 Thread spir
On Thu, 30 Dec 2010 07:46:19 +0100 Don wrote: > This problem has already hit Phobos. We inserted a hack so that sqrt(2) > will work. But exp(1) doesn't work. > Note that the problems really arise because we've inherited C's rather > cavalier approach to implicit conversion. I'm unsure of the p

Re: PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-29 Thread Robert Jacques
On Wed, 29 Dec 2010 23:46:19 -0700, Don wrote: BACKGROUND: D currently uses a very simple rule for parameter matching: * it matches exactly; OR * it matches using implicit conversions; OR * it does not match. There's an important extra feature: polysemous literals (those which can be interpr

PROPOSAL: Implicit conversions of integer literals to floating point

2010-12-29 Thread Don
BACKGROUND: D currently uses a very simple rule for parameter matching: * it matches exactly; OR * it matches using implicit conversions; OR * it does not match. There's an important extra feature: polysemous literals (those which can be interpreted in multiple ways) have a preferred interpretat