Value Preservation and Polysemy

Don nospam at nospam.com
Mon Dec 1 06:46:59 PST 2008


Andrei Alexandrescu wrote:
> I've had a talk with Walter today, and two interesting things transpired.
> 
> First off, Walter pointed out that I was wrong about one conversion rule 
> (google value preservation vs. type preservation). It turns out that 
> everything that's unsigned and less than int is actually converted to 
> int, NOT unsigned int as I thought. This is the case in C, C++, and D.

That has some interesting consequences.

   ushort x = 0xFFFF;
   short y = x;
   printf("%d %d %d\n", x>>1, y>>1, y>>>1);

// prints: 32767 -1 2147483647

What a curious beast the >>> operator is!

> I'm very excited about polysemy. It's entirely original to D, covers a 
> class of problems that can't be addressed with any of the known 
> techniques (subtyping, coercion...) and has a kick-ass name to boot. 

I agree. By making the type system looser in the one place where you 
actually need it to be loose, you can tighten it everywhere else. Fantastic.




More information about the Digitalmars-d mailing list