-
Notifications
You must be signed in to change notification settings - Fork 19
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
Some type-parameter grabbing code is very opaque #127
Comments
Currently we define struct ClassicalIntensityFormula{T} <: IntensityFormula
kT :: Float64
formfactors
string_formula :: String
calc_intensity :: Function
end Note that In this context: typeof(formula).parameters[1].parameters[2] I think @Lazersmoke said that To avoid these tricks in the type system, I wonder if we can move struct ClassicalIntensityFormula <: IntensityFormula
type_info :: <<perhaps a tuple of types >>
kT :: Float64
formfactors :: Any
string_formula :: String
calc_intensity :: Function
end |
Yep I like Kip's proposal to move it to value level. The real issue here is that Julia |
For future reference, I thought this wouldn't work, but it does! Julia automatically reifies type-level parameters to data-level as needed (this is different than, say, Java). I still think it's better that we keep the information at the data level explicitly, but this is interesting to know. struct Foo{ImportantData} end
many_foos = Foo[]
push!(many_foos, Foo{42}(), Foo{43}())
many_foos[1]
many_foos[2]
@assert typeof(many_foos[1]).parameters[1] == 42
@assert typeof(many_foos[2]).parameters[1] == 43 |
Resolved in #288. |
Arcane:
https://github.com/SunnySuite/Sunny.jl/blob/b852192d0044effe21bf66684e57f1879d6d4953/src/Intensities/LinearSpinWaveIntensities.jl#L67C19-L67C62
The text was updated successfully, but these errors were encountered: