julia

Whats the replacement for typealias in Julia?


julia> typealias
ERROR: UndefVarError: typealias not defined

it's working in Julia:0.5 but is not working in above versions

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}

So is there any other function or keyword that can be used and works the same way?


Solution

  • There are two ways to define a type alias, which can be seen in the following example:

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

    You can see that both of these type aliases are equivalent to the built-in Vector type alias:

    julia> Vector
    Array{T,1} where T
    

    See Type Aliases and UnionAll Types in the manual for more information.