I am wondering about types in Julia, more specific Union
. For instance, I have made a function where I add the length of my input a
into a vector len_a
. If a
is of type VariableRef
I want the length to be 1. I write it like this;
function add_length!(a::VariableRef,lenComp::Vector, i::Int)
len_a[i] = 1.0;
end
However, if a
is not of type VariableRef
I want it to take the length. So I am wondering if I should do as I have done below, like defining a new type by using Union
:
NotVariableRef = Union{Vector, NonlinearExpression, QuadExpr, AffExpr}
function add_length!(a::NotVariableRef,len_a::Vector, i::Int)
len_a[i] = length(a)
end
or if I should do it like this;
function add_length!(a::Any,len_a::Vector, i::Int)
len_a[i] = length(a)
end
What is the "right" way of doing it? And is this: len_a::Vector, i::Int)
alright or should I have something like len_a::Vector{Int}, i::Int64)
. I am a bit confused by this type system.