On Friday, 29 May 2015 10:37:38 UTC-3, Yichao Yu wrote:
>
> On Fri, May 29, 2015 at 9:21 AM, andrew cooke <[email protected] 
> <javascript:>> wrote: 
> > 
> > Ahh! 
> > 
> > No, its possible: 
> > 
> > 
> > julia> foo(::Nullable{Union()}) = "empty" 
> > foo (generic function with 1 method) 
> > 
> > julia> foo(::Nullable{Int}) = "int" 
> > foo (generic function with 2 methods) 
> > 
> > julia> foo(Nullable()) 
> > "empty" 
> > 
> > julia> foo(Nullable(4)) 
> > "int" 
>
> I'm not sure if this is what you want. 
>
> The point of Nullable is that it maintains type stability when you 
> return "missing value", i.e. the type of a Nullable you should get 
> from a function should always be the same (otherwise there's no point 
> to use Nullable to begin with).


can you expand on this?  what if i'm writing some code that constructs 
arbitrary types, and i need to know whether the user constructed 
"anything", or decided to not do so on this call.  wouldn't that be a 
suitable use of Nullable{Any}?
 


In a function that returns Int or a 
> missing value, you return either Nullable(<int value>) or 
> Nullable{Int}(). 
>
> Unfortunately, this means that you cannot dispatch on the type (since 
> there's only one and that's the point). IMHO, depending on your 
> usecase, you might be better off branching on whether the Nullable has 
> a value. 
>
> > 
> > 
> > Sorry, please ignore! 
>

Reply via email to