I have created a data structure of this sort
abstract type Node end
struct Tree{A <: Node, B <: Node} <: Node
a::A
b::B
end
This type of structure allows me to conveniently address nodes of a tree by the type of the children.
As an example I can have
struct Character <: Node
c::Char
end
and make a specialized method that recognizes a tree with two Character children
function test(node::Tree{Character, Character}) end
But I could also potentially define a function like
function test(node::Tree{Tree{Character, Character}, Tree}) end
which address a Tree with the leftmost branch containing two Character and an arbitrary Tree on the right one.
My implementation dispatches many methods in a similar fashion.
This type of structure works, but for quite large trees I have noticed some slowdowns, especially when trying to determine the types using typeof. Is this pattern considered efficient? If not, is there a way to make it more efficient?