Julia <;的含义是什么:朱莉娅?

Julia <;的含义是什么:朱莉娅?,julia,Julia,有人能帮我写这段代码吗 struct GenericPoint{T<:Real} x::T y::T end struct GenericPoint{T首先,我要说的是,手册的这一页是搜索此类运算符的便捷方法,否则使用搜索引擎很难找到此类运算符。 在的具体案例中,它的意思是“是的子类型”:虽然我仍然认为这是一个重复,但答案是一个非常好的总结。您可以补充一点,案例3实际上是参数化方法的一个特例,它只约束构造函数方法(GenericPoint{String}仍然是一个有效的东西!)@phip

有人能帮我写这段代码吗

struct GenericPoint{T<:Real}
x::T
y::T
end
struct GenericPoint{T首先,我要说的是,手册的这一页是搜索此类运算符的便捷方法,否则使用搜索引擎很难找到此类运算符。

的具体案例中,它的意思是“是的子类型”:虽然我仍然认为这是一个重复,但答案是一个非常好的总结。您可以补充一点,案例3实际上是参数化方法的一个特例,它只约束构造函数方法(
GenericPoint{String}
仍然是一个有效的东西!)@phipsgabler实际上,如果我键入
GenericPoint{String},我会得到一个
TypeError
进入Julia 1.5版的REPL。也许你指的是一个已经修复的旧行为?哦,酷。我仍然有1.3版,并且一直认为它只是语法上的糖分。需要仔细阅读一下。啊,我太傻了。我用
struct Typ测试了它{T@phipsgabler是的,你说得对,这是一份副本。我很抱歉:我没有更早地看到你对此的评论,而且当我完成键入此答案时,我没有勇气放弃它。因此我很虚弱,不管怎样都将其发布:/
julia> Int <: Number
true

julia> Int <: AbstractString
false
# `Foo` is declared to be a subtype of `Number`
struct Foo <: Number
end
julia> struct GenericPoint{T<:Real}
           x::T
           y::T
       end

# Works because 1 and 2 are of type Int, and Int <: Real
julia> GenericPoint(1, 2)
GenericPoint{Int64}(1, 2)

# Does not work because "a" and "b" are of type String,
# which is not a subtype of Real
julia> GenericPoint("a", "b")
ERROR: MethodError: no method matching GenericPoint(::String, ::String)
Stacktrace:
 [1] top-level scope at REPL[5]:1
julia> foo(x::Vector{T}) where {T<:Number} = "OK"
foo (generic function with 1 method)

# OK because:
# - [1,2,3] is of type Vector{Int}, and
# - Int <: Number
julia> foo([1, 2, 3])
"OK"

# Incorrect because:
# - ["a", "b", "c"] is of type Vector{String}, but
# - String is not a subtype of Number
julia> foo(["a", "b", "c"])
ERROR: MethodError: no method matching foo(::Array{String,1})