[julia-users] Nullable parametric types

2015-07-21 Thread Darwin Darakananda
Hi all,

I'm in the process of replacing my Union{Nothing, T} annotations to 
Nullable{T}, but I'm getting stuck when T is a parametric type.  For 
example, replacing the function

function myfunc(v::Union{Nothing, Vector})
...
end

with

function myfunc(v::Nullable{Vector})
...
end

makes it completely uncallable since any vector I pass in comes with an 
eltype parameter and Julia's type parameters are invariant.  For functions 
or types that only have a couple Nullable types, I can do something like

function myfunc{T}(v::Nullable{Vector{T}})
...
end

type MyType{T}
   v::Nullable{Vector{T}
end

but that gets very ugly when you have a large number of nullable types. 
 Does anyone know of a cleaner way to do this?

Thanks,

Darwin


Re: [julia-users] Nullable parametric types

2015-07-21 Thread Mauro
If I understand correctly, this should do:

function myfunc{T:Vector}(v::Nullable{T})
...
end


On Tue, 2015-07-21 at 22:37, Darwin Darakananda darwinda...@gmail.com wrote:
 Hi all,

 I'm in the process of replacing my Union{Nothing, T} annotations to 
 Nullable{T}, but I'm getting stuck when T is a parametric type.  For 
 example, replacing the function

 function myfunc(v::Union{Nothing, Vector})
 ...
 end

 with

 function myfunc(v::Nullable{Vector})
 ...
 end

 makes it completely uncallable since any vector I pass in comes with an 
 eltype parameter and Julia's type parameters are invariant.  For functions 
 or types that only have a couple Nullable types, I can do something like

 function myfunc{T}(v::Nullable{Vector{T}})
 ...
 end

 type MyType{T}
v::Nullable{Vector{T}
 end

 but that gets very ugly when you have a large number of nullable types. 
  Does anyone know of a cleaner way to do this?

 Thanks,

 Darwin