@test isequal_type(Type{Tuple{Vararg{Int,N}} where N}, Type{Tuple{Vararg{Int,N} where N}})
@test Type{Tuple{Vararg{Int,N}} where N} !== Type{Tuple{Vararg{Int,N} where N}}
julia> Type{Tuple{Vararg{Int,N}} where N} == Type{Tuple{Vararg{Int,N} where N}}
true
julia> Type{Tuple{Vararg{T,2}} where T} == Type{Tuple{Vararg{T,2} where T}}
false
let A = Tuple{Vararg{Val{N}, N} where N},
B = Tuple{Vararg{Val{N}, N}} where N,
C = Tuple{Val{2}, Val{2}}
@test isequal_type(A, B)
@test issub(C, B)
@test issub(C, A)
end
julia> Tuple{Vararg{Val{N}, N} where N} == Tuple{Vararg{Val{N}, N}} where N
true
julia> Tuple{Vararg{Val{N}, 2} where N} == Tuple{Vararg{Val{N}, 2}} where N
false
julia> Tuple{Vararg{Val{2}, 2}} == Tuple{Vararg{Val{2}, 2}}
true
julia> Tuple{Vararg{Val{N}, 2} where N <: Integer} == Tuple{Vararg{Val{N}, 2}} where N <: Integer
false
不是很懂
又看到一个相关的测试,不过没搞清楚 @testintersect 宏的功能
# part of issue #20344
@testintersect(Tuple{Type{Tuple{Vararg{T, N} where N}}, Tuple} where T,
Tuple{Type{Tuple{Vararg{T, N}}} where N where T, Any},
Bottom)
julia> g(x::T...) where T = nothing
g (generic function with 1 method)
julia> g(1,2)
julia> g(1,:a)
ERROR: MethodError: no method matching g(::Int64, ::Symbol)
Closest candidates are:
g(::T...) where T at REPL[6]:1
Stacktrace:
[1] top-level scope at none:0
而不会这么写:
julia> h(x::T where T...) = nothing
ERROR: syntax: invalid variable expression in "where"
julia> m(x::Vararg) = x
m (generic function with 1 method)
julia> m
m (generic function with 1 method)
julia> methods(m)
# 1 method for generic function "m":
[1] m(x...) in Main at REPL[24]:
如果希望所有的参数都有相同的类型,那么这样写:
julia> n(x::Vararg{T}) where T = x
n (generic function with 1 method)
julia> methods(n)
# 1 method for generic function "n":
[1] n(x::T...) where T in Main at REPL[27]:
终于到了这个帖子的主题了,问题在于,还有下面这种写法:
julia> o(x::Vararg{T} where T) = x
o (generic function with 1 method)
julia> methods(o)
# 1 method for generic function "o":
[1] o(x...) in Main at REPL[30]: