In general, Julia code should try to do conversion here. Allow the second argument to be anything and then try converting it to the element type of the container. If that doesn't work, it will throw a runtime error.
On Thu, Feb 27, 2014 at 8:42 AM, Cristóvão Duarte Sousa <cris...@gmail.com>wrote: > I wondered how > a = Array(Number, 0) > push!(a, 3) > works, and I found > https://github.com/JuliaLang/julia/blob/0f1ccefcd172de74bcd68774fd734f29c72c1f83/base/array.jl#L487. > So I think that a > v = convert(T, v) > or maybe a > @assert isa(v, T) > is the Julian way to go :) > > > On Thursday, February 27, 2014 5:39:35 AM UTC, Fil Mackay wrote: > >> type A{T} >> end >> >> function f{T}(a::A{T}, v::T) >> end >> >> a = A{Number}() >> f(a, 3) >> >> #no method f(A{Number}, Int64) >> #while loading In[4], in expression starting on line 7 >> >> >> Is there a reason why the Int64 parameter does not get accepted as a Number >> in the above? Especially when this method is accepted by the match: >> >> >> function f(a::A{Number}, v::Number) >> println("$a $v") >> end >> >> >> f(a,3) >> >> # no errors >> >> >>