When you create an inner constructor, it deletes all default constructors. So 
you have to provide the default outer constructor:

    TLPixel{T}(img:Image{T}) = TLPixel{T}(img)

Despite appearances, {T} on the left hand side is very different from {T} on 
the right: on the left it's acting as a parameter for dispatch, on the right 
it's declaring the type you want to create. You could, of course, put some 
other type in there:

    TLPixel{T<:Integer}(img:Image{T}) = TLPixel{Float32}(img)
    TLPixel{T<:FloatingPoint}(img:Image{T}) = TLPixel{T}(img)


If you believe that this information is missing from the documentation, please 
take the time to improve it:
https://github.com/JuliaLang/julia/edit/master/doc/manual/constructors.rst
(click on the pencil icon).

--Tim

On Friday, December 05, 2014 06:35:56 AM Andrew Gibb wrote:
> I want to create a parametric type whose parameter is inferred from the
> parameter of an argument. A toy example:
> 
> using Images
> 
> type TLPixel{T}
>     data::T
>     function TLPixel(img::Image{T})
>         new(img.data[1,1])
>     end
> end
> 
> If I do this:
> 
> julia> tlp = TLPixel{typeof(img.data[1,1])}(img)
> 
> This works fine. However, I would have expected the dispatcher(?) to
> realise that the parameter on the image, T, is the same as the one in the
> type declaration. But it doesn't:
> 
> julia> tlp = TLPixel(img)
> `TLPixel{T}` has no method matching TLPixel{T}(::Image{RGB{UfixedBase{Uint8,
> 8}},2,Array{RGB{UfixedBase{Uint8,8}},2}})
> while loading In[4], in expression starting on line 1
> 
> 
> Have I done something wrong here, or should I not expect this to work?

Reply via email to