Anything can be an expression (or part of an expression) in Julia. Eg
julia> immutable Foo x end
julia> dump(:(x + $(Foo(9))))
Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol +
2: Symbol x
3: Foo
x: Int64 9
typ: Any
so Foo(9)
is just sitting there as an argument until +
is called, and it is not an Expr
, which :(Foo(9))
would be. (See this comment on a question I asked recently for related concepts).
More related to your application: I imagine a symbol eg :x
is also symbolically differentiable, and it is not an expression. So don’t restrict the types.
Finally, you may find this library useful: