Julia: Should Union types record whether they came from a defining typealias?

Created on 14 Oct 2016  路  4Comments  路  Source: JuliaLang/julia

There's now a number of issues open for thoughts about how to make the printing of types more readable. Here's another notion: it would be nice if printing could replace Unions with appropriate typealiases. For example:

julia> methods(permutedims)
#2 methods for generic function "permutedims":
permutedims(B::Union{Base.ReshapedArray{T<:Any,N<:Any,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray{T<:Any,N<:Any},SubArray{T<:Any,N<:Any,A<:Union{Base.ReshapedArray{T<:Any,N<:Any,A<:DenseArray,MI<:Tuple{Vararg{Base.MultiplicativeInverses.SignedMultiplicativeInverse{Int64},N<:Any}}},DenseArray},I<:Tuple{Vararg{Union{Base.AbstractCartesianIndex,Colon,Int64,Range{Int64}},N<:Any}},L<:Any}}, perm) at multidimensional.jl:959
permutedims{T,N}(A::AbstractArray{T,N}, perm) at permuteddimsarray.jl:47

But the first method is actually defined as permutedims(B::StridedArray, perm) which is rather simpler to read.

This is easy to point out, but actually implementing it seems likely to be hard starting from the jl_uniontype_t itself. Unless Union types get modified to record whether they come from a typealias.

Most helpful comment

The printing code could search for globals === to a particular union type. We could potentially have an ObjectIdDict mapping unions to their "names". Not sure if that's necessary, but it could even be part of the lowering of typealias, giving that syntax a bit of extra value over const assignment.

Showing names for instantiations of these unions is of course harder, but after #8974 it will at least be possible to brute-force search globals for supertypes of a given union type.

All 4 comments

The printing code could search for globals === to a particular union type. We could potentially have an ObjectIdDict mapping unions to their "names". Not sure if that's necessary, but it could even be part of the lowering of typealias, giving that syntax a bit of extra value over const assignment.

Showing names for instantiations of these unions is of course harder, but after #8974 it will at least be possible to brute-force search globals for supertypes of a given union type.

I was worried that brute-force search would be too inefficient, but maybe we wouldn't typically have that many typealiases. https://github.com/JuliaMath/FixedPointNumbers.jl/pull/51 exports a few hundred typealiases, but none of those are Unions.

Duplicate of #14946?

Yup.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omus picture omus  路  3Comments

iamed2 picture iamed2  路  3Comments

Keno picture Keno  路  3Comments

omus picture omus  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments