What Happend To Tango Graphic's Package

Christopher Wright dhasenan at gmail.com
Wed Sep 26 17:44:58 PDT 2007


Reiner Pope wrote:
> 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);
> }

For primitives, it is an implementation detail and you need not concern 
yourself. It only need be something that can handle the entire range of 
any of the possible values.

For user-defined types, well, that's the polysemous type:

class A {
   // As per the slides, these two make A polysemous.
   int opImplicitCastTo() { ... }
   byte opImplicitCastTo() { ... }
}

A something () { ... }

void main () {
   auto foo = something(); // typeof(foo) == A
   if (foo & 0b0011000)    // yields int, or byte, or something
     writefln("Fuzzy pattern!");
   else
     writefln("Funny pattern!");
}

I'm not sure this will make it into the language except for primitives. 
There, it's useful mainly because of literals.



More information about the Digitalmars-d mailing list