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?
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.
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!"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With