What Happend To Tango Graphic's Package

Reiner Pope some at address.com
Tue Sep 25 23:03:47 PDT 2007


Christopher Wright wrote:
> Reiner Pope wrote:
>> Don Clugston wrote:
>>> Christopher Wright wrote:
>>>> Janice Caron wrote:
>>>>> On 9/24/07, Chad J <gamerChad at _spamisbad_gmail.com> wrote:
>>>>>> I hope polysemous types come out and solve this mess.
>>>>>
>>>>> What does "polysemous type" mean? What are polysemous types?
>>>
>>> For example, the literal number 1. Could be a short, int, uint, 
>>> float, complex number,...
>>> Strict typing forces us to assign a type to it, but actually they're 
>>> all the same.
>>>
>>>>
>>>> A variable that can have several types depending on how it is 
>>>> assigned or casted is polysemous. Walter wants to use this 
>>>> especially for string literals -- should it be fixed length or not, 
>>>> should it be char, wchar, dchar?
>>>
>>> It should kill signed/unsigned type mismatches forever, too.
>>> It's really a fantastic concept.
>>
>> Can someone explain how it works?
>>
>>  From the slides, I can make a few guesses about it, but none of them 
>> seems to fit with everything on the slides.
>>
>> Guess #1: it's a form of type inference which is more powerful than 
>> "auto" because it examines use as well as the initial assignment.
>>
>> A number of other languages do this, and it's very nice, but it seems 
>> not to gel with the statement, "if it is used in a context where sign 
>> does matter ... then an error is issued."
>>
>> Guess #2: algebraic data types/discriminating unions/some other fancy 
>> name.
>>
>> The example, "function results (polysemous: result type or error 
>> type)" suggests this. In Haskell syntax, this might be the type,
>>
>> data FunctionResult = Result Int | Error String
>>
>> so the result is a union of a string and an int; pattern matching is 
>> used to check if it's an result or an error.
>>
>> However, this doesn't seem to relate to the rest of the examples.
> 
> Well, that is a variable whose type depends on a runtime execution path. 
> A polysemous type is the same value, but the type of that value can 
> change based on compile time usage. Maybe on runtime usage:
> 
> ---
> void foo (uint i) {}
> void bar (long j) {}
> PolysemousIntegerType getval () { return 0; } // syntax for polysemy?
> 
> void main (char[][] args) {
>    auto i = getval();
>    if (args.length == 0) {
>       foo(i);
>    } else {
>       bar(i);
>    }
> }
> 
> Except I don't think the auto keyword will work with polysemous types, 
> at least not initially.

I understand your example to mean that it is some kind of integer type, 
and the casts may be omitted. Is there some other feature to it?

But how is the variable actually stored? uint? long?

It *must* be clearly defined, otherwise the following program would be 
undefined:

void main() {
     auto i = getval(); // i is polysemous as defined above, with value 0
     while (i < 1)
         --i;

     writefln(i);
}

I just realised that the comparison is disallowed by polysemy as per 
WalterAndrei.pdf. However, even if a type is polysemous between long and 
ulong don't problems occur when decrementing? When you decrement 0L you 
get -1L; when you decrement 0LU you get ulong.max; now the two types no 
longer have the same value.

Or is there a special way of representing the numbers so they behave the 
same way?

---

Perhaps polysemous types involve actually choosing a specific definition 
of the variable's representation in memory; in that case, "polysemous 
integer types" seems to be another word for "long, but it is implicitly 
convertable to all the other integer types."

---

Thanks for your help.

    -- Reiner



More information about the Digitalmars-d mailing list