Macro's are way harder than parameterized types. I would avoid them in
general. All that templating you are doing is simply creating a less
powerful parameterized type with a lot more code. Here's the same
thing, parameterizing Node on some symbol T which describes it.
immutable Node{T}
children::Vector{Node}
Node() = new( Node[] )
Node( children ) = new( children )
end
Node(T::Symbol) = Node{T}()
# I'll throw in a typealias, just 'cause. this isn't necessary
# but helps to show the purpose of typealiases
typealias NodeA Node{:A}
abstract Visitor
type MyVisitor <: Visitor end
function visit{T}(v::MyVisitor, n::Node{T})
println("hello subtype ", T, " of node: ", n)
end
#show off the various constructor patterns:
a = NodeA()
b = Node{:B}()
c = Node(:C)
d = Node{:D}(Node[])
push!(a.children, b)
# a is immutable, so a.children = [b] is invalid
# but the a.children array is still mutable
push!(a.children, c)
push!(a.children, x)
println("node a: ", a)
visit(MyVisitor(), a)