朱莉娅中的typealias替代品是什么?

时间:2020-01-15 19:12:40

标签: julia

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}

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

1 个答案:

答案 0 :(得分:6)

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

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