I am having some issues understanding the concept of parametric constructors in Julia. I am looking at the standard example in the Julia docs:
struct Point{T<:Real}
x::T
y::T
end
To my understanding, this means I can generate a Point-datatype with an input that is subtype of Real, i.e., AbstractFloat, AbstractIrrational, ..., Integer, Rational, ..., StatsBase.TestStat.
However, both of the examples below result in errors:
Point(Integer(12))
Point(Rational(12))
Why does the above fail given that both integer and rational are subtypes of real?
The type parameter goes inside the curly braces in the constructor call, just like it does in the
structdefinition:The arguments supplied are the values for the fields of the struct i.e.
xandy. If the arguments are already of the type you want, you can leave out explicitly specifying the type parameter: