When writing some methods for show
for types in a package, I was wondering if there is any mechanism (or package) for reusing show
methods for fields but nesting the indentation.
Eg suppose a type prints as
This is a Foo with 3x2 elements.
[1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0]
and a type Bar
prints as
This is a Bar with critical value 0.7
Then for a type Baz
struct Bar
foo::Foo
bar::Bar
end
is there an organized way to write a show
method that
- reuses
show
code for the fields, - indents the fields.
Eg
This is a Bar with fields
This is a Foo with 3x2 elements.
[1.0 1.0 1.0; 1.0 1.0 1.0; 1.0 1.0 1.0]
This is a Bar with critical value 0.7
Solutions I have thought of:
- use something other than indentation, eg
•
, - pass around the current indentation as an optional 3rd argument of
show
, defaulting to0
.
Neither of these is very clean.