julia - Julia 中 typealias 的替代品是什么?
问题描述
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
有关详细信息,请参阅手册中的类型别名和UnionAll 类型。
推荐阅读
- bots - Telegram Webhook 和 Ngrok 无法正常工作
- asp.net-core - 你如何处理这么多 index.cshtml 页面?
- postgresql - 如何从文件中的数据库中进行选择?
- testing - 如何使用 hasura 对微服务进行集成测试?
- r - Excel 可以读取 .Rdata 或 .RDS 苍蝇吗?
- android - 重新排列带有 2 个线性布局的 XML 文件
- google-bigquery - 来自 Microstrategy 的 Bigquery 用户统计信息
- wordpress - 过期标头无法识别
- java - 单击按钮而不是重新启动时,计时器继续滴答作响
- python - 官方 PyPI 与非官方二进制文件