If performance matters, currently you're going to have to specify the element
type---not for the sake of your `MyType` object, but simply for the efficient
access to elements of c and d. This will change once
https://github.com/JuliaLang/julia/pull/15921 merges. On julia 0.4, you could
write your own version of a function that looks like the definition of `vect`
in that PR.
In cases where c and d have different element types, you can write a variant of
foo{T}(x::T, y::T) = T
foo(x, y) = foo(promote(x, y)...)
It will be a little more complicated because you'll have to call `convert`
explicitly rather than just using promote, but hopefully you get the idea.
Best,
--Tim
On Monday, April 18, 2016 01:20:36 AM Patrick Kofod Mogensen wrote:
> Say I have something like
>
> type MyType{T}
> a::T
> b::Vector{T}
> c::Vector{Vector{T}}
> d::Vector{Matrix{T}}
> end
>
> MyType(3, [3, 3], Vector{Int64}[[3,3], [4,4]], Matrix{Int64}[[3 1],[1 3]])
>
> MyType(3, [3, 3], Vector[[3,3], [4,4]], Matrix[[3 1],[1 3]])
>
>
> The first call to the MyType constuctor will work, but the second one will
> not, because the Vector[...] and Matrix[...]'s are not told that they are
> only going to contain arrays of integers.
>
> Say I want to provide users with a type such as MyType, but I don't want
> them to write {Float64} or {Int64} all the time. What is the best way to
> allow the second call to MyType?
>
> Patrick