Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the replacement for typealias in Julia?

Tags:

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?

like image 279
Mayank Khurana Avatar asked Jan 15 '20 19:01

Mayank Khurana


People also ask

What is mutable struct in Julia?

type and immutable are valid up to julia 0.6, mutable struct and struct are the names of the same objects in julia 0.6 and forward. mutable in mutable struct means that the fields can change - which is actually fairly rarely used so being immutable is the default. mutable struct 's are slower than struct s.

What is Union in Julia?

Type Unions A type union is a special abstract type which includes as objects all instances of any of its argument types, constructed using the special Union keyword: julia> IntOrString = Union{Int,AbstractString} Union{Int64, AbstractString} julia> 1 :: IntOrString 1 julia> "Hello!" :: IntOrString "Hello!"


Video Answer


1 Answers

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.

like image 129
Cameron Bieganek Avatar answered Sep 24 '22 08:09

Cameron Bieganek