Hi Glen,
Perhaps in my previous email when I wrote:
f(1, 2, 3) rather than f((1, 2 , 3))
I should have written something like f(1, 2.3, 5 +
3.im, 3 + 1im, Nullable{Float64}(5.)) to make it explicit that I would like to parametrise different types. I think David Gold's suggestion is the closest to what I want but doesn't quite solve the problem. If I wanted to lift a set of Julia's functionality to new types having an arbitrary set of input types, I could:
1. Spend alot of time writing code to parse different subsets of modules. This would take an immense amount of work and the libraries would inevitably change.
2. If we could model a variadic template function having the semantics as I specified previously:
function {T...}my_fun(x...)
for i in 1:length(x)
println(typeof(x[i]) <: T[i])
end
end
The above function for simplicity. Here T... are the types of x... and they could be all different or the same
We could lift functionality of all the relevant function in one go with a sketch implementation like:
# Import the functions ...
import Base: get, +, -, /, *, ^, ...
# Function symbols to be lifted
funs = [:+, :-, ...]
# Generic get function
# Assume appropriate get functions are written for each type
function get{T}(x::T)
x
end
# My new type is T1{T}()
S = Union{Symbol, Expr}
# My lifter function
function lift(fun_name::S, new_type::S)
quote
function $fun_name{T...}(x...)
y = Array(Any, length(x))
y[i] = get(i)
end
ret = $fun_name(y...)
U = typeof(ret)
return $new_type{U}(ret)
end
end
end
# Then lift the functions
for i in funs
eval(lift(i, :T1))
end
Could then do T1(3.4) + 9 and so on for all the functions regardless of number of arguments return type etc