Getting the parametric constructors from `methods`

CameronBieganek
Sun, 26 Mar 2023 15:16:50 +0000
General Usage

If I call methods(Dict), it just returns the “non-parametric constructors”:

julia> methods(Dict)
# 5 methods for type constructor:
[1] Dict() in Base at dict.jl:118
[2] Dict(ps::Pair{K, V}...) where {K, V} in Base at dict.jl:124
[3] Dict(kv::Tuple{}) in Base at dict.jl:119
[4] Dict(ps::Pair...) in Base at dict.jl:125
[5] Dict(kv) in Base at dict.jl:127

I can get the “parametric constructors” with a call like this:

julia> methods(Dict{Int,Int})
# 6 methods for type constructor:
[1] Dict{K, V}() where {K, V} in Base at dict.jl:88
[2] Dict{K, V}(d::Dict{K, V}) where {K, V} in Base at dict.jl:92
[3] Dict{K, V}(p::Pair) where {K, V} in Base at dict.jl:108
[4] Dict{K, V}(ps::Pair...) where {K, V} in Base at dict.jl:109
[5] Dict{K, V}(kv) where {K, V} in Base at dict.jl:100
[6] Dict{K, V}(slots, keys, vals, ndel, count, age, idxfloor, maxprobe) where {K, V} in Base at dict.jl:96

However, I had hoped to be able to use a call like methods(Dict{K,V} where {K,V}), but that just returns the “non-parametric constructors”. Is there a more generic way of getting the UnionAll constructor methods for a type, rather than calling methods on a specific instance like Dict{Int,Int}?

3 posts - 2 participants