Le vendredi 04 juillet 2014 à 08:24 -0700, Ben Ward a écrit :
> If I define a parametric type:
> 
> type MyType{T}
>   firstval::T
>   secondval::T
> end
> 
> 
> Can specific methods then be written for specific forms of MyType? For
> example a method that only worked for MyType containing Int64 as T? I
> haven’t tried this yet - I've run into my first real world application
> of parametric types.
Sure, just try it:
julia> type MyType{T}
         firstval::T
         secondval::T
       end

julia> a = MyType(1, 2)
MyType{Int64}(1,2)

julia> b = MyType(1.0, 2.0)
MyType{Float64}(1.0,2.0)

julia> f(x::MyType{Int}) = "a"
f (generic function with 1 method)

julia> f(x::MyType{Float64}) = "b"
f (generic function with 2 methods)

julia> f(a)
"a"

julia> f(b)
"b"


Regards

Reply via email to