I've been trying to understand this particular section towards the end of the style guide, but seem to be going round and round in circles. A stripped down version is shown below.
The definition of Unit_e and Diag_e goes directly against what is suggested in that section (I think). I've seen another reference/suggestion, based on a baremodule in GTK.jl. But that did not lead to easier to read code. I've also seen other recent threads, but to me none easy to grasp. Maybe another example candidate? Initially I set out to be able to use the form used to assign to l in below code fragment. Hmc() is part of several larger composite types, but that just seems a repeated use of this structure. Any suggestions how to do this properly in Julia? Regards, Rob J. Goedman [email protected] ------------------------------------------------------------ abstract Metrics type Unit_e <: Metrics end type Diag_e <: Metrics end abstract Algorithm type Hmc <: Algorithm # ... metric::Metrics end type Fixed_param <: Algorithm end Hmc() = Hmc(Diag_e()) Hmc(m::DataType) = ( m <: Metrics ? Hmc(m()) : "Error: $(m) not a subtype of Metrics" ) Hmc(m::Symbol) = ( eval(m) <: Metrics ? Hmc(eval(m)()) : "Error: $(m) not a subtype of Metrics" ) h = Hmc() l = Hmc(Diag_e) k = Hmc(:Unit_e) @assert isa(h.metric, Metrics) @assert isa(l.metric, Metrics) @assert isa(k.metric, Metrics) @assert typeof(k.metric) <: Metrics
