[Grace-core] Typing of Number

Andrew P. Black black at cs.pdx.edu
Mon Jun 20 22:27:53 PDT 2011


On 20 Jun 2011, at 20:29, James Noble wrote:

>>>> As it stands the specification says that the standard library will try
>> to coerce any Number to an integral when used as an index. Will it not
>> do that? If it does, what happens for Binary64?
> 
> argh. I don't know. Perhaps that's not the Right Thing to say.

This is surely up to the object being indexed.  For some objects, with continuous behavior, having non-integral indexes makes perfect sense.  For others, it does not.   
> 
>> In a purely structurally-typed world I'm not sure how the numeric
>> types are distinguished anyway. I can come up with methods that would
>> be unique to Rationals and IEEE floating-point types, but a
>> hypothetical Integer32 and Integer64 seem like they'd implement
>> exactly the same interface and be type aliases.

Do you mean "distinguished from each other" or "distinguished from non-numeric types"?

Binary64 and Binary128 have the same behavior as types.  And maybe that's exactly right: you want to be able to replace the Binary64 constructor methods by Binary128 constructors, and have the program continue to be type-correct, but with a more exact result. 

> right. 
> or you start introducing fake marker methods "I am int32" or something

There is of course an efficiency argument for prohibiting re-implementation of integer: if you can tell from the type that a value has the particular built-in machine integer representation, you can emit machine instructions rather than method requests.  But it precludes the nice automatic conversion to BigNums that are so convenient.  Didn't we have some principles that covered this.

Another place to look for inspiration is the numeric types in Fortress.  A lot of smart mathematically-inclined people thought very hard about those.  But Fortress uses types to define semantics.

	ANdrew
 


More information about the Grace-core mailing list