Creating a simple convert method?


#1

I’ve been going through the example for writing a convert method and i just can’t get it to work in what should be this very simple case.

Thanks

import Base: -, +, convert

export Point, convert

type Point{T<:Number}
x :: T
y :: T
z :: T
end

function convert{T<:Float64}(::Type{T}, xyz::Tuple{Float64,Float64,Float64})
Point(xyz[1], xyz[2], xyz[3])
end
edit:
ERROR: MethodError: Cannot convert an object of type Tuple{Float64,Float64,Float64} …


#2

I think you want ::Type{Point{T}}


#3

yes- that was the problem.

naturally, i caught that mistake right after i posted (why, why does that always happen ?)

Thanks.