# What happened to \`T?\`

**URL:** https://discourse.julialang.org/t/what-happened-to-t/25480
**Category:** Internals & Design
**Tags:** question
**Created:** [June 20, 2019, 11:28am UTC](https://discourse.julialang.org/t/what-happened-to-t/25480 "2019-06-20T11:28:59Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)
#### Post date: [June 20, 2019, 11:29am UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/1 "2019-06-20T11:29:00Z")

</div>

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

```julia
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?

```julia
m(T) = Union{T, Missing}
macro m(T)
    :(Union{$T, Missing})
end

```

don’t work in function definitions

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [June 20, 2019, 11:54am UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/2 "2019-06-20T11:54:11Z")

</div>

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

> [@Aliases for Union{T, Nothing} and Union{T, Missing}?](https://discourse.julialang.org/t/aliases-for-union-t-nothing-and-union-t-missing/15402/41):
>
> How about @?Int? ex = frowning macro \_(ex) if $(rand() \> 0.5) :(Union{$ex, Nothing}) else :(Union{$ex, Missing}) end end ) ex.args[1].args[1] = :? eval(ex) @?Int

---

<div class="post-metadata">

### Author: ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)
#### Post date: [June 20, 2019, 12:26pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/3 "2019-06-20T12:26:15Z")

</div>

cool macro, scares me to use it in production code 😨

---

<div class="post-metadata">

### Author: ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)
#### Post date: [June 20, 2019, 12:29pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/4 "2019-06-20T12:29:41Z")

</div>

of course without the random `Nothing`/`Missing` switch

---

<div class="post-metadata">

### Author: ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)
#### Post date: [June 20, 2019, 12:42pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/5 "2019-06-20T12:42:01Z")

</div>

Why? If you are living on the edge already… 😉

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [June 20, 2019, 12:48pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/6 "2019-06-20T12:48:44Z")

</div>

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

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

```

(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).

---

<div class="post-metadata">

### Author: ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)
#### Post date: [June 20, 2019, 2:47pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/7 "2019-06-20T14:47:28Z")

</div>

> [@gdkrmr](#):
>
> Is there still a plan to integrate this into julia?

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

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 20, 2019, 3:01pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/8 "2019-06-20T15:01:01Z")

</div>

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…?

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [June 20, 2019, 4:39pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/9 "2019-06-20T16:39:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [June 20, 2019, 4:59pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/10 "2019-06-20T16:59:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)
#### Post date: [June 20, 2019, 5:52pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/11 "2019-06-20T17:52:58Z")

</div>

I like this one:

```julia
const U = Union
const M = Missing
U{Float64, M}

```

- No magic macros
- Explicit
- Short enough

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [June 20, 2019, 6:08pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/12 "2019-06-20T18:08:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 20, 2019, 6:50pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/13 "2019-06-20T18:50:08Z")

</div>

> [@ExpandingMan](#):
>
> U(T,Missing)

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

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [June 20, 2019, 6:54pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/14 "2019-06-20T18:54:40Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 20, 2019, 7:04pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/15 "2019-06-20T19:04:44Z")

</div>

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 🙂

---

<div class="post-metadata">

### Author: ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)
#### Post date: [June 20, 2019, 7:23pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/16 "2019-06-20T19:23:37Z")

</div>

I keep defining

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

```

And I’m OK with that.

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 20, 2019, 7:25pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/17 "2019-06-20T19:25:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)
#### Post date: [June 20, 2019, 7:26pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/18 "2019-06-20T19:26:00Z")

</div>

To handle both `missing` and `nothing` perhaps:

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

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 20, 2019, 7:28pm UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/19 "2019-06-20T19:28:12Z")

</div>

`Neh` works then for Nothing…

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [June 21, 2019, 5:06am UTC](https://discourse.julialang.org/t/what-happened-to-t/25480/20 "2019-06-21T05:06:51Z")

</div>

> [@ExpandingMan](#):
>
> I recall that @Tamas_Papp had some nice suggestion for an alternative

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.

> [@Aliases for Union{T, Nothing} and Union{T, Missing}?](https://discourse.julialang.org/t/aliases-for-union-t-nothing-and-union-t-missing/15402/11):
>
> I think that extensions don’t break 1.0, so in theory they would be OK. That said, I prefer Union{T, Missing} & similar. I am sure I would have a hard time remembering which of Maybe, Option, and other variants corresponds to which singleton (as the discussion demonstrates, this is not intuitive at all); just as I don’t remember precedence tables so I try to avoid relying on them.
