I guess I am lacking knowledge of design patterns,
can someone suggest the right solution (common in Julia) to set of specific modules that reexport general module functionality with one argument inserted?
The general module defines functions that depend on a state
(require the state as an input).
I what to have a set of specific modules that do not require typing the state
explicitly.
module General
export state, st1, st2
struct state{T}
par1::T
par2::T
end
st1 = state(1.1, 2.2)
st2 = state(2.2, 3.3)
# methods
export calculation, someothercalculation
calculation(x, s::state) = 2x * s.par1 + s.par2
someothercalculation(x, s::state) = 3x * s.par1 + s.par2
end
The specific modules implement the same methods for specific states, these are now for single-argument.
module Specific1
using Reexport
@reexport using General
export st
st = st1
import General: calculation, someothercalculation
calculation(x) = calculation(x,st)
someothercalculation(x) = someothercalculation(x,st)
end
to create Specific2
I actually would duplicate the Specific1
code except for the st = st1
line,
that become st = st2
.
There must be a better way.
8 posts - 3 participants