gpt4 book ai didi

julia - Julia 中 typealias 的替代品是什么?

转载 作者:行者123 更新时间:2023-12-04 18:18:10 26 4
gpt4 key购买 nike

julia> typealias
ERROR: UndefVarError: typealias not defined

它在 Julia:0.5 中有效,但在以上版本中无效
help?> typealias
search: typealias

Introduce a new name for an already expressible type. For example, in
base/boot.jl, UInt is type aliased to either UInt64 or UInt32 as appropriate
for the size of pointers on the system:

if is(Int,Int64)
typealias UInt UInt64
else
typealias UInt UInt32
end

For parametric types, typealias can be convenient for providing names in
cases where some parameter choices are fixed. In base for example:

typealias Vector{T} Array{T,1}

那么有没有其他函数或关键字可以使用并以相同的方式工作?

最佳答案

定义类型别名有两种方式,可以在下面的例子中看到:

julia> const MyVector1 = Array{T,1} where T
Array{T,1} where T

julia> MyVector2{T} = Array{T,1}
Array{T,1} where T

可以看到这两个类型别名等价于内置的 Vector类型别名:
julia> Vector
Array{T,1} where T

Type AliasesUnionAll Types在手册中了解更多信息。

关于julia - Julia 中 typealias 的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59758148/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com