# Proposed alias for union types

**URL:** <https://discourse.julialang.org/t/proposed-alias-for-union-types/108205>\
**Category:** Internals & Design\
**Tags:** question, proposal\
**Created:** [December 31, 2023, 1:43pm UTC](https://discourse.julialang.org/t/proposed-alias-for-union-types/108205 "2023-12-31T13:43:56Z")\
**Posts on this page:** 1\
**Showing post:** 84

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [January 3, 2024, 10:37am UTC](https://discourse.julialang.org/t/proposed-alias-for-union-types/108205/84 "2024-01-03T10:37:39Z")

</div>

> [@Tamas\_Papp](#):
>
> the `|` syntax for type unions should be explored in a package

I created a package at [GitHub - mkitti/OrUnions.jl: Julia package to evaluate alternate Union syntax via | and ∨](https://github.com/mkitti/OrUnions.jl) . To avoid piracy I used `∨` (\vee) rather than `|`.

```julia
julia> 0x5::(UInt8 ∨ Int8)
0x05

julia> f(x::(Int8 ∨ UInt8 ∨ Int)) = x
f (generic function with 1 method)

```

If you really want to use `|`, I created a macro called `@orunion`.

```julia
julia> @orunion function foo(::Int8 | UInt8 | Int16) end
foo (generic function with 1 method)

julia> methods(foo)
# 1 method for generic function "foo" from Main:
 [1] foo(::Union{Int16, Int8, UInt8})
     @ REPL[34]:1

julia> @macroexpand @orunion function foo(::Int8 | UInt8 | Int16) end
:(function foo(::Union{Int16, UInt8, Int8})
      #= REPL[36]:1 =#
      #= REPL[36]:1 =#
  end)

julia> @orunion bar(x::Int8 | UInt8, y::Int16 | UInt16, z::(Int8 | UInt8) | Int) = nothing
bar (generic function with 1 method)

julia> methods(bar)
# 1 method for generic function "bar" from Main:
 [1] bar(x::Union{Int8, UInt8}, y::Union{Int16, UInt16}, z::Union{Int64, Int8, UInt8})
     @ REPL[38]:1

julia> @macroexpand @orunion bar(x::Int8 | UInt8, y::Int16 | UInt16, z::(Int8 | UInt8) | Int) = nothing
:(bar(x::Union{UInt8, Int8}, y::Union{UInt16, Int16}, z::Union{Int, Union{UInt8, Int8}}) = begin
          #= REPL[40]:1 =#
          nothing
      end)

julia> methods(@orunion (x::Int8 | UInt8)->5)
# 1 method for anonymous function "#35":
 [1] (::var"#35#36")(x::Union{Int8, UInt8})

```

---

_[View the full topic](https://discourse.julialang.org/t/proposed-alias-for-union-types/108205)._
