What happened to `T?`

If memory serves me, once upon a time there was a proposal to simplify syntax for missing values:

T? == Union{T, Missing}

Currently I have to handle a lot of missing values and find the extra typing quite annoying.

  • Is there still a plan to integrate this into julia?
  • How do other people handle this?
m(T) = Union{T, Missing}
macro m(T)
    :(Union{$T, Missing})

don’t work in function definitions

1 Like

You can write f(x::@?(Int), y::Int) = x+y with tkf’s clever macro, from this earlier discussion:


cool macro, scares me to use it in production code :fearful:

1 Like

of course without the random Nothing/Missing switch

Why? If you are living on the edge already… :wink:

1 Like

Would it make sense to add this at the beginning of your project?

for T in collection_of_types
    @eval const $(Symbol(T, :_)) = Union{$T, Missing}

(with collection_of_types being a collection of all the types with possible missing values you are working with, and replacing :_ by any suitable symbol you want to append to the type names for aliasing them).

1 Like

There is no consensus whether it should mean Union{T, Nothing} or Union{T, Missing}.

1 Like

I’d rather have one of them (which ever) than none at all… I guess we could scan all the registered packages and see what it more common, Missing or Nothing…?

T? for one, T?? for the other?

I’m pretty sure I’ve mentioned this elsewhere, but I just want to repeat that I think that T? is really ugly syntax. The first reason for this is that there are very few right unary operators in Julia. The only exception I am aware of is ', which I think is a much better case because the notation for adjoint or transpose as a right unary operator is universal (something that cannot be said for a short-hand of Union{T,Missing}). The second reason is that the logical implication syntax a ? b : c is valid and often used in Julia, and when I see T? my first instinct is that I’m looking at a broken ternary operation.

I recall that @Tamas_Papp had some nice suggestion for an alternative, but I can’t remember what it was at the moment, it might have been something like U(T,Missing). I also think it would be nice to have a notation that might be a little bit of extra typing, but is both explicit about whether it is using Nothing, Missing or something else, and general enough to be extensible to all binary type unions.


I like this one:

const U = Union
const M = Missing
U{Float64, M}
  • No magic macros
  • Explicit
  • Short enough

M seems very mysterious and ad hoc to me. I find the T? notation to be fantastic, and the other suggestions verbose and cumbersome.


T U Missing makes a lot of sense to me. Simply having Union as an infix operator makes it a lot prettier.

1 Like

That rings a bell, I think @Tamas_Papp’s original suggestion may have been

∪(T::Type, S::Type) = Union{T,S}

As in [1,2,3] ∪ [4,5,6] the union (small ‘u’) of two types is a Union (capital ‘U’) type of the two. No idea what Tamas said :slight_smile:

I keep defining

const Maybe{T} = Union{T, Nothing}

And I’m OK with that.

How about Meh{T} instead? Shorter and funnier.


To handle both missing and nothing perhaps:

const Maybe{T} = Union{T, Missing}
const Naybe{T} = Union{T, Nothing}

Neh works then for Nothing…


I can’t recall anything, sorry. In fact, I think I was against any clever syntax, I find the explicit Union{...} much cleaner. For frequent application one can always define an alias.

1 Like