Value Preservation and Polysemy -> context dependent integer literals
Fawzi Mohamed
fmohamed at mac.com
Thu Dec 4 14:33:23 PST 2008
On 2008-12-04 18:54:32 +0100, Andrei Alexandrescu
<SeeWebsiteForEmail at erdani.org> said:
> Fawzi Mohamed wrote:
>> On 2008-12-01 22:30:54 +0100, Walter Bright <newshound1 at digitalmars.com> said:
>>
>>> Fawzi Mohamed wrote:
>>>> On 2008-12-01 21:16:58 +0100, Walter Bright <newshound1 at digitalmars.com> said:
>>>>
>>>>> Andrei Alexandrescu wrote:
>>>>>> I'm very excited about polysemy. It's entirely original to D,
>>>>>
>>>>> I accused Andrei of making up the word 'polysemy', but it turns out it
>>>>> is a real word! <g>
>>>>
>>>> Is this the beginning of discriminating overloads also based on the
>>>> return values?
>>>
>>> No. I think return type overloading looks good in trivial cases, but as
>>> things get more complex it gets inscrutable.
>>
>> I agreee that return type overloading can go very bad, but a little bit
>> can be very nice.
>>
>> Polysemy make more expressions typecheck, but I am not sure that I want that.
>> For example with size_t & co I would amost always want a stronger
>> typechecking, as if size_t would be a typedef, but with the usual rules
>> wrt to ptr_diff, size_t,... (i.e. not cast between them).
>> This because mixing size_t with int, or long is almost always
>> suspicious, but you might see it only on the other platform (32/64
>> bit), and not on you own.
>>
>> Something that I would find nice on the other hand is to have a kind of
>> integer literals that automatically cast to the type that makes more
>> sense.
>
> Wouldn't value range propagation take care of that (and actually more)?
> A literal such as 5 will have a support range [5, 5] which provides
> enough information to compute the best type down the road.
>
> Andrei
Exactly, my point was to apply this only to integer literals, if I had
understood correctly you thought to apply it to everything.
As I said with size_t & co actually I would like a tighter control, and
range propagation gives me a more lax control.
With integer literals on the other hand I think range propagation or
similar is a good idea.
(because there I am sure that preserving the value is the correct choice)
Fawzi
More information about the Digitalmars-d
mailing list