[Grace-core] Typing of Number

Kim Bruce kim at cs.pomona.edu
Mon Jun 20 23:55:07 PDT 2011


> 
>> If you want to define only Rational + Rational, Binary64 + Binary64,
>> ..., then the type probably really needs to be something like:
>> type Number<T> {
>>   +(other : Number<T>) -> Number<T>
>> }
>> Number isn't doing a lot there though.
> 
> type Number {
> +(other: selfType) -> selfType 
> }
> 
> which your proposed earlier would do it - although of course
> it's not at all clear what "selfType" means in a structural world (is it?)

Almost all my work on "MyType" or "SelfType" is with structural types, there are no added problems there.
> 
>> I do think that if there's a
>> Rational type it should be possible to constrain yourself to remaining
>> within it somehow.
> 
> right.
> 
>> I also think Number + Number ought to work other
>> than in very exceptional cases, by the principle of least surprise.
> 
> that's where things get odd.
> 
> The other thing Go does is (statically) type constants to "the right (static) type".
> It's not so clear how we'd do this dynamically.
> One option would be to have a "ConstantExact" or "ConstantInexact" type
> which is a subtype of all the various other types so that constants work
> properly even through the selfType.   ARGH.
> 
> (note that this would mean the selfType was *not* an exact selfType).
> But that probably opens us up to yet more horrible issues I don't understand.

I had two different type systems in LOOM and then LOOJ.  In the first, everything had an exact type unless you labeled it (with #T) as a matching type.  With LOOJ, types were as in Java (x declared to have type T meant at run-time it was a T or an extension), while exact types needed to be labeled (@T).  Both worked well.  I've seen a more recent proposal from some people who worked on Fortress where SelfType (MyType) is always exact, while others are not.  Any of these variations can work.  I kind of like the last one, but the LOOJ-style system may be less jarring for people if we decide to have a SelfType.

Kim


More information about the Grace-core mailing list