Output the same type of struct in function

  1. typeof(plan2) == PLAN2{Univariate,Float64} and, indeed, there is no function PLAN2{Univariate,Float64}(a, b) but only PLAN2(a, b) defined. If you want the type without parameters, you can get it with typeof(plan2).name.wrapper, but I would disencourage relying on “internal” fields like name and wrapper. I don’t know what the best approach would be here, but one possibility is to define functions initialize(model::PLAN1, a, b) = PLAN1(a, b) and initialize(model::PLAN2, a, b) = PLAN2(a, b).
  2. I suspect that you have a performance decrease. I would benchmark this with BenchmarkTools.

By the way, and sorry for raising this when you didn’t ask for it, but I think the outer constructor of PLAN2 can be simplified, e.g. PLAN2(a, b, c = Dict(:∅ => [])) = ... and it is always worth reading a bit in the Julia style guide, in particular here.

1 Like