[julia-users] Inferring constructor parameters from parameters of arguments

2014-12-05 Thread Andrew Gibb
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)

Re: [julia-users] Inferring constructor parameters from parameters of arguments

2014-12-05 Thread Mauro
you have to provide an outer constructor as well when you define an inner one. This is a bit confusing, have a look at the manual search the list. Here using your example using Arrays as I don't know Images: type TLPixel{T} data::T function TLPixel(img::Array{T}) new(img[1])

Re: [julia-users] Inferring constructor parameters from parameters of arguments

2014-12-05 Thread Tim Holy
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