-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trait-based dispatch of number methods #155
Comments
I would propose using @MasonProtter's idea from JuliaLang/julia#37790 (comment) of how to do type tags in the current type system. Sym{ModelingToolkit.Parameter{Real}} is a non-extendable version of this, and interferes with the current rules handling. If it's always Sym{Real,{ModelingToolkit.Parameter}}, then the contextual information is all in extendable tags and the rules can be written to use the algebraic set of the first part. |
The inevitable problem is how do we make sense of many tags? I really like the idea of these type tags, but then I think about Sym{Real, Tuple{Parameter, Tag2, Tag3, Tag4}} and I realize that anyone who handles this thing is going to need to know not just what |
I guess if we have a rule that "tags must be ignorable" we could probably be okay and then use That means that to go back to the motivating example in the other thread, |
I think the rule for the symbolic case is "tags must be ignorable". For something like |
Union sounds interesting. But how do you dispatch on just Parameter when you have a Union tag? |
Here's a MWE: struct Tag1 end
struct Tag2 end
struct Tag3 end
struct Parameter end
struct Sym{T, U}
name::Symbol
end
f(x::Sym{Real, Union{Parameter, Other}}) where {Other} = "hi"
f(x::Sym{Real, Union{Other}}) where {Other} = "bye"
x = Sym{Real, Union{Tag1, Tag2, Parameter, Tag3}}(:x)
y = Sym{Real, Union{Tag1, Tag2, Tag3}}(:y) julia> f(x)
"hi"
julia> f(y)
"bye" |
Note however, there's trouble if you put a |
Parameter{X<:Number} type from ModelingToolkit is used as a parameter as in
Symbolic{Parameter{X}}
, but that means methods insrc/methods.jl
cannot be restricted toSymbolic{<:Number}
because it won't work on MTK parameters.There are 2 approaches to fixing this:
Symbolic{<:Number}
-- not yet sure how the whole system will work when adding a new type. See here for an example of this kind of circus@number_methods
work based on dispatch and disregardSymbolic{T}
, or optionally just eliminate the type parameter and useSymbolic
.The text was updated successfully, but these errors were encountered: