Stream: helpdesk (published)

Topic: Does it matter if Unions are const?


view this post on Zulip Mark Kittisopikul (Aug 15 2022 at 19:32):

I recently noticed that StridedArray is a Union that is not const. I usually make my unions const like other globals that I declare, but now I'm wondering if it actually matters or not.

view this post on Zulip Mason Protter (Aug 15 2022 at 20:29):

In modern versions of julia, writing a type alias with the curly brackets has an implicit const.

julia> Foo{T} = Union{Vector{T}, Tuple{T, Int}}
Union{Vector{T}, Tuple{T, Int64}} where T

julia> Foo{T} = Union{Vector{T}, Tuple{T, Int, Int}}
ERROR: invalid redefinition of constant Foo

view this post on Zulip Mason Protter (Aug 15 2022 at 20:29):

I forget when we added this behaviour

view this post on Zulip Mark Kittisopikul (Aug 15 2022 at 21:46):

Cool. I never noticed.

view this post on Zulip Michael Abbott (Aug 15 2022 at 21:47):

Would be nice to list such things under ?const


Last updated: Nov 06 2024 at 04:40 UTC