ANN: StructuralInheritance.jl

This package can be used to create concrete types that inherit structure or can have structure inherited from.

Most of the functionality is in the @protostruct macro. This macro simultaneously creates a concrete and abstract type. Creating a method for the abstract type can take advantage of the shared structure for types descended from it. By default, the name of the abstract type has the prefix Proto on top of the name of the concrete type, though this behavior can be changed by putting a different prefix following the struct definition.

There is also functionality for emulating super constructors. The method StructuralInheritance.totuple can be used along with splatting and a constructor for the type that is being inherited from to fill the fields in the inherited type with what would have been found in the structural super type.

This package supports Julia versions 0.7 or greater.


Nice! :slight_smile:

Just quick idea after I briefly looked at it.

From help for inspiration:

help?> @doc


The @doc macro can be used directly to both set and retrieve documentation / metadata. By default, documentation is written as Markdown, but any object can be placed
  before the arrow. For example:

  @doc "blah" ->
  function foo() ...

  The -> is not required if the object is on the same line, e.g.

  @doc "foo" foo

You could think how to add doc to Foo and ProtoFoo by your macro or you could just add

@doc "Cool C struct" C

into your to show how to do this manually and avoid this:

help?> C
search: C cp cd Cmd Char csc cot cos cmp cld cis cat Cint Core Cvoid csch cscd coth cotd cosh cosd cosc copy conj chop ceil cbrt Cuint Colon Clong Cchar const ccall catch ctime count cospi

  No documentation found.

This is just amazing!

Thanks! I wanted to keep the readme true to what a user would experience but didn’t really like the whole search: C cp cd Cmd Char csc ... part. Also good point, I should show how to add documentation to types defined by the macro.