Just to be clear, are you looking for something that will parameterise
across a variety of types, or are you wanting to restrict to a single type?
If the latter, it can be easily done with
function mycode{T}(x::T...)
<code here>
end
which will make all values in the varargs list the same. To restrict to a
specific subset, there's also
function mycode(x::Union(Int,Array)...)
<code here>
end
which will require that the arguments in x be either Ints or Arrays (and
can have both).
If you're actually after the former, is there a reason why you can't just
ask for typeof(x[i]), directly? Alternatively, would this work?
function mycode{T}(x...;t::T=x)
for j=1:length(x)
println(typeof(x[j])<:T[j])
end
end
On Monday, 5 October 2015 09:32:57 UTC+10, [email protected] wrote:
>
> Thanks David, that gets me part of the way there but is there a way of
> specifying the x argument as a varag so that the function can be called as:
>
> f(1, 2, 3) rather than f((1, 2 , 3)) this is useful if I am trying to
> "lift" a bunch of functions that already exist to play with new types. For
> instance I could then call plus on the new types T1(value1) + T2(value2)
> retaining the natural semantics of the functions.
>
> DP
>
>
> On Monday, October 5, 2015 at 12:03:33 AM UTC+1, David Gold wrote:
>>
>> Note that if the type variable T does not appear in the argument
>> signature then the method won't be callable.
>>
>> If you really want to make use of the variable parameters, your best bet
>> I think is to pass a tuple of args:
>>
>> function f{T<:Tuple}(x::T)
>> for (i, param) in enumerate(T.parameters)
>> println(typeof(x[i]) <: param)
>> end
>> end
>>
>> This (or some variant, I forget) can also make the types of the
>> individual xs available at compile time.
>>
>>
>>
>> On Saturday, October 3, 2015 at 7:22:49 PM UTC-7, [email protected]
>> wrote:
>>>
>>> Is it possible to specify a variable number of parameter types in Julia,
>>> for instance something like
>>>
>>> function {T...}my_fun(x...)
>>> for i in 1:length(x)
>>> println(typeof(x[i]) <: T[i])
>>> end
>>> end
>>>
>>> should print true ... times
>>>
>>> Thanks
>>>
>>