I want to propose a little addition to subset type definitions.
They should get an implementation body like classes and roles.
This is useful to add methods to the type. Here is my Rectangle
example from the 'how to change the type of objects' thread.

# @.points contains Point objects
subset Rectangle of Polygon where { [EMAIL PROTECTED] == 4 && ...}
   # new methods
   method width  { return (@.points[1] - @.points[0]).abs }
   method height { return (@.points[2] - @.points[1]).abs }

   # overridden method from Polygon
   method area { return self.width * self.height }

The content of such a definition might be restricted to methods
because I don't see how adding state with a has declarator could
work. Depending on the where clause the object's data would need
to be augmented with the additional slots.

We could continue the subtype chain with

subset Square of Rectangle where { .width == .height };

The semicolon might be necessary because it indicates the empty
definition body. Or could the definition block be completely

BTW, can a subset definition also be based on a role?

Regards, TSa.

Reply via email to