struct A{T<:Real, N}
a::T
A{N}(a::T) where {T,N} = new{T,N}(a)
end
For this simple parametric type, A{2}(1.0) fails with a TypeError,
ERROR: TypeError: in A, in T, expected T<:Real, got a value of type Int64
I find this extremely unintuitive. Why is type assertion T<:Real in the definition of the parametric type A applied to a parameter of its constructor? Am I using the parametric constructors incorrectly?
In other words, it’s an upper bound on a type, not a type assertion for an instance. typeassert(object, type) and the syntax object::type in some contexts is a type assertion, and it’s not currently supported in where clauses, including the implicit one in struct definitions.
I thought constructors are just methods that have the same name as the composite type. Being callable objects indeed makes a lot more sense. Thanks again for clearing up my confusion!