I am trying to create a structure where parameter types can either be given explicitly or are inferred automatically from the arguments. However, I also would like to define the inner constructor method, such as in the following example:
struct A{T}
x :: T
A{T}(a) where T = new(a^2)
end
When I explicitly give the type, it works fine, e.g.,
julia> A{Float64}(2)
A{Float64}(4.0)
However, when the type is not explicitly given, it raises the following error:
julia> A(2)
ERROR: MethodError: no method matching A(::Int64)
Stacktrace:
[1] top-level scope at none:0
What do I need to do in order to be able to have parametric types that can be inferred or given explicitly with an explicit inner constructor?