I’d like to user-friendly interface in my simulator.
So, I don’t wanna force users to add some specific struct fields.
However, I encountered some issues in my usage pattern.
FymEnv is a type given by my package, and
Env will be user-defined struct.
f (meaning update proceduer in simulator) will be the user-defined function for simulation.
integral is provided by the package.
I’d like to record
Env's property (=env’s
size, namely) once (which can be calculated at the beginning of simulation) and reuse it to enhance simulation performance.
Here is that looks like what I want:
struct Env <: FymEnv a # something end function f(env::Env) a = env.a integral(env) # how to refer its size inside `integral` without attaching field `size`? return a # just an illustrative example end
integral requires env’s size and calculate it at every instant may make the performance bad.
Of course, I may force users to add field
size to their struct
Env but it’s quite annoying to me because the envs. can be very large and nested.
On the other hand, if I provide another struct (
FymSym, namely) as follows,
struct Sim <: FymSym env::Env size end
users have to consider it and change the function
function f(sim::FymSym) a = sim.env.a # annoying integral(sim) # can get size by `sim.size` inside `integral` return a # just an illustrative example end
If there any good idea to solve it?
For more details, this issue is originally from avoiding exhausted calculation of the size of state, addressed in LazyFym.jl.