Thanks Jameson. Here's what I ended up with:
immutable NTSeries{N, T}
coefficients::NTuple{N, T}
NTSeries(a...) = new(a)
end
NTSeries(a...) = NTSeries{length(a), eltype(promote(a...))}(promote(a
...)...)
NTSeries(1.0, 2.0)
# NTSeries{2,Float64}((1.0,2.0))
NTSeries(1//2, 5)
# NTSeries{2,Rational{Int64}}((1//2,5//1))
This version does promotion to a common type, similar to [...] array
literals.
A couple other resources that I found helpful:
http://docs.julialang.org/en/latest/manual/constructors/#parametric-constructors
http://stackoverflow.com/questions/25670614/julia-why-must-parametric-types-have-outer-constructors
https://github.com/JuliaLang/julia/issues/8234
On Friday, October 9, 2015 at 7:15:14 PM UTC-4, Jameson wrote:
>
> Since you replaced the inner constructor with an explicit one, you also
> need to define an outer constructor.
>
> On Fri, Oct 9, 2015 at 7:13 PM Jason Merrill <[email protected]
> <javascript:>> wrote:
>
>> I'm trying to make a wrapper around an NTuple that takes varargs, but I
>> can't figure out what the constructor should look like. I thought the
>> following would work, but it throws an error
>>
>> jwm@jason-2 ~/s/julia> julia
>> _
>> _ _ _(_)_ | A fresh approach to technical computing
>> (_) | (_) (_) | Documentation: http://docs.julialang.org
>> _ _ _| |_ __ _ | Type "?help" for help.
>> | | | | | | |/ _` | |
>> | | |_| | | | (_| | | Version 0.4.0 (2015-10-08 06:20 UTC)
>> _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release
>> |__/ | x86_64-apple-darwin13.4.0
>>
>> julia> immutable NTSeries{N, T}
>> coefficients::NTuple{N, T}
>>
>> NTSeries(a...) = new(a)
>> end
>>
>> julia> NTSeries(1.0, 2.0)
>> ERROR: MethodError: `convert` has no method matching convert(::Type{
>> NTSeries{N,T}}, ::Float64, ::Float64)
>> This may have arisen from a call to the constructor NTSeries{N,T}(...),
>> since type constructors fall back to convert methods.
>> Closest candidates are:
>> call{T}(::Type{T}, ::Any)
>> convert{T}(::Type{T}, ::T)
>> in call at essentials.jl:57
>>
>> Any pointers?
>>
>