Hi, I'm completely new to Nim. Does nim support natural transformations?
Natural transformations allow type regulation through inheritance.
Widget -> NewWidget
| |
v v
Button -> NewButton
class Widget;
class Button : Widget { Widget[] Children; }
class NewWidget : Widget;
class NewButton : NewWidget, Button;
The general problem is that as we generalize the widget model, the base typing refers only to base typing and does not generalize.
If Button contains a collection of Widgets, for example(such as labels, icons, etc), then our NewWidget would also contain such a collection, BUT we want them to use NewWidget and not Widgets! This generally is faulty since or NewWidget may need to hold any Widget(After all, it is technically a Button).
But this causes problems with the modeling since we want to generalize the entire model. Most languages
What we would like to have is
class NewButton : NewWidget, Button { NewWidget[] Children; }
With Children being the object in Button. But what is important is that the type now reflects the appropriate type in the extended model. We don't have to cast the type to NewWidget. The usage of the model precludes adding non NewWidget's to Children. If we were to cast a NewButton to a Button then we could violate the model but the design itself precludes this, when a model is extended, it is done so in it's entity.
Such models are used to generalize preexisting models and are used in such a way that they preserve the entire structure. Essentially we are just using the structure of the base model to create a new model and, being models, we do not mix two derived models and therefor there is no issues with variances. If the language is not capable to dealing with this, it becomes clumsy since type checking and casting must be constantly used or very verbose patterns take's it's place, with it, it's no more complicated than the original base model. For it to be effective though, the language must have some concept of modeling in it.
So what does Nim say?