Chapel supports embedding of classes to express a more seamless composition of types. This is similar to inheritance in other object-oriented languages.
To run the program, save it as struct_embedding.chpl and use the Chapel compiler:
In this Chapel version, we use inheritance to achieve a similar effect to Go’s struct embedding. The Container class inherits from the Base class, allowing it to access all of Base’s fields and methods.
Chapel doesn’t have interfaces, but we can achieve similar functionality using abstract classes or by relying on duck typing. In this example, we’ve used a generic function printDescription that can work with any object that has a describe() method.
This demonstrates how Chapel can express concepts similar to Go’s struct embedding, albeit with some differences due to its object-oriented nature.