julia中的“whereT”在T之后没有任何说明的情况下做什么?
我是朱莉娅的新手,我无法找到where对我来说完全有意义的解释。所以我明白,例如
function f(x::T, y::T) where {T<:Number} = true要求 x 和 y 参数都是某种数字类型。
但是还有其他函数看起来像function f(X::AbstractMatrix{T}) where T没有任何关于 T 应该是什么的规范。有人可以解释一下它在做什么以及我什么时候想使用这种语法吗?
回答
where T没有其他任何东西只是where {T<:Any}换句话说,对所有人都是如此T,但是 Julia 需要你写一些东西,以便定义 `T。
- You have access to `T` inside the function body of the latter definition. That's it.
- the other - tiny - difference is that Julia will ignore `@nospecialize` for the definition using the `where T` approach.