@Araq
Well, I don't think it's possible to use generics in this solution. As far as I
know, Rust's trait objects are implemented in a similar manner and they lack
generic methods (that's one of the reasons why it's often advised to use
generic traits rather than generic methods within non-generic traits).
As for data/method separation... sadly, you won't be able to split these into
more than one module. However, it would be entirely possible to write a macro
(quite a simple one at that!) to automate what you said. It would probably look
like this:
class Shape:
...
proc hash = ...
proc area: float = ...
class Square of Shape:
...
proc hash {.override.} = ...
proc area: float {.override.} = ...
proc side: float = ...
let squareShape: Shape = Square(...)
echo squareShape.area # here, the square variant is called because area
_field_ is set to square's one
echo squareShape.side # compile-time error, of course