Thank you; that did the trick (with `Coefficients{T}(vals::Vector{T}) = 
Coefficients{T}(vals)` defined outside the type).
The fact that defining Coefficients{T} does not necessarily define Coefficients 
seems like an awfully subtle point, though it is mentioned in 
http://docs.julialang.org/en/release-0.4/manual/constructors/:
<quote>
Some features of parametric constructor definitions at work here deserve 
comment. First, inner constructor declarations always define methods of 
Point{T} rather than methods of the general Point constructor function. Since 
Point is not a concrete type, it makes no sense for it to even have inner 
constructor methods at all. Thus, the inner method declaration Point(x,y) = 
new(x,y) provides an inner constructor method for each value of T. It is this 
method declaration that defines the behavior of constructor calls with explicit 
type parameters like Point{Int64}(1,2) and Point{Float64}(1.0,2.0). The outer 
constructor declaration, on the other hand, defines a method for the general 
Point constructor which only applies to pairs of values of the same real type. 
</quote>

It's even trickier because the definition that makes Coefficients without the 
type work looks exactly like (on the left) the declaration which does not have 
the desired effect, Coefficients{T}.

Does the language have to work this way?
Ross
________________________________________
From: [email protected] [[email protected]] on behalf of 
Yichao Yu [[email protected]]
Sent: Friday, May 27, 2016 6:02 PM
To: Julia Users
Subject: Re: [julia-users] Why isn't my constructor recognized?

On Fri, May 27, 2016 at 7:53 PM, Boylan, Ross <[email protected]> wrote:
> A type is defined as
> type Coefficients{T}
>     raw::Vector{T}
>     σ_0::T
>     σ_T::T
>     ρ::T
>     ν::T
>     Σ::Matrix{T}
>     # because of this c'tor the type must be mutable
>     function Coefficients(vals::Vector{T})

This defines a method for `Coefficients{T}` and needs to be called
with `Coefficients{T}(...)` and not `Coefficients(...)`
Defining a inner constructor turns off the automatically defined
construction (method for `Coefficients`) that automatically deduce the
type parameter so you need to manually define that constructor with
`Coefficients{T}(vals::Vector{T}) = Coefficients{T}(vals)` (note that
the first `{T}` is a parameter for this method of `Coefficients`, the
last `{T}` uses this variable to instantiate `Coefficients` and then
call the `Coefficients{T}` object instead.)

Reply via email to