[Grace-core] an old thread on singleton types (Was: Aside from Abstract)

James Noble kjx at ecs.vuw.ac.nz
Tue Jan 7 03:01:36 PST 2014


> I just found this old thread on singleton types.  It implies that the only method that a type object need have is match.  While match is necessary, it does not seem to me to be sufficient; don't type also need a way of asking what methods are in the type, ands what their argument and result types are?   SingletonTypes could delegate this to a mirror on their distinguished object, but more general type would surely implement such methods.

There seem to be two possible things here:
 - iterating through all the methods in a type, getting their names, arguments, types etc
 - asking if a particular method is in a particular type.  (respondsTo in Smalltalk)

IIteration through everything sounds reflexive to me.  It just does. Perhaps we shouldn't make that distinction.

for the question of "does an object of type Foo have method m" 
you can always make the type of just method m
and either match against it

def o : Foo = ... 

(type { method m -> Number }).match ( o )   // test object explicitly

or perhaps types can support the <: operator or some other method testing subtypes

so you could just write (Foo <: Bar)   
or if (Foo <: type { method m -> Number } ) 

James


More information about the Grace-core mailing list