chromatic wrote:
Why would a class not also define a type?

It does. A class is an instance generator. So all instances
share the same property of 'beeing instanciated from SomeClass'.
This can be used to type them. Question is where this type is
placed in the type lattice and how it compares to the type of
structurally/semantically identical objects beeing instanciated
from another class.

My proposal is to hang the type off the top, most unspecific
type Any or actually a bit further down, under Object
which excludes Package, Module, Class, Grammar and Role.

The name of the class is inserted in the appropriate place into
the namespace and is available as type parameter for the Ref[::T]

It is actually quite interesting that there is no special form
for compile time object instantiation with the keyword object.

   class Point
      has Num $.x;
      has Num $.y;

   object center of Point  # without of we get classless objects
      .x = 23;
      .y = 42;

   object pi of Num = 3.14;

   our Int object answer = 42;

   say answer;  # prints 42
   say center.x # prints 23

   # and even more

   our Array object some_values = (1,2,3,4,5);

   for some_values { say }

Hmm, looks somewhat unperlish :))
TSa (Thomas Sandlaß)

Reply via email to