Hello all,
For Soss.jl I’d like a cleaner way of manipulating and reasoning about ASTs. Currently a Model
is nearly just an expression:
hello = @model μ begin
σ ~ HalfCauchy()
x ~ Normal(μ, σ)
end
builds
julia> hello.args
1-element Array{Symbol,1}:
:μ
julia> hello.body
quote
σ ~ HalfCauchy()
x ~ Normal(μ, σ)
end
Currently all of the manipulations are just moving things around using MacroTools. It works, but it feels very error-prone.
It feels like it could be useful to have something with typed variable binding information. For example (line by line)
@macro μ begin
Hmm, ok μ
is bound but we don’t yet know the type
σ ~ HalfCauchy()
Now we know σ
is a positive real, μ
is still bound but type is still unknown
x ~ Normal(μ, σ)
After the final line, x
is also bound, and we now know x
and μ
are both real.
I’m not sure exactly what I’m looking for, but it seems like if there were a typed system for representing this it could be very useful for the kinds of transformations I’m working toward. To be really fancy, careful typing could even disallow invalid transformations.
I had initially thought S-expressions could be useful:
julia> Meta.show_sexpr(hello.body)
(:block,
(:call, :~, :σ, (:call, :HalfCauchy)),
(:call, :~, :x, (:call, :Normal, :μ, :σ))
)
but there’s no type or binding info. code_typed
is great but too low-level for the current goal.
Anything existing that can use for this, or suggestions for building something?