Julia Types Summary
Table of Contents
1 Overview
This summary is written for Julia v0.3.x, and it is NOT a tutorial, you can get more about julia types on http://julia.readthedocs.org/en/latest/manual/types/.
2 All Types of Julia
- Declared Types
- Abstract Type,
e.g.
abstract Number
Bits Type
bitstype «bits» «name» bitstype «bits» «name» <: «supertype» bitstype 128 Uint128 <: Unsigned
Composite Type, e.g.
type Foo bar baz::Int qux::Float64 end
Imutable Composite Type, e.g.
immutable Complex real::Float64 imag::Float64 end
- Abstract Type,
e.g.
- Type Union,
e.g.
Union(T1, T2)
- Type Tuple
- type of a tuple is a
Type Tuple
- e.g.
typeof((1, 1.0))
is(Int64, Float64)
(Any...,)
is the same asTuple
- type of a tuple is a
Type Aliases
#typealias DestType SourceType typealias Uint Uint64
Parametric Types
type Point{T} x::T y::T end
- Parametric Abstract Types, e.g.
abstract Pointy{T}
- Parametric Abstract Types, e.g.
- Meta Types
- Type
- DataType, UnionType
- Type{T} (Singleton Type)
- Special Types
- Top: Union type of all types
- None: Union type of none type (
Union()
) - Any: Root spuer type of all declared type(like
Object
in Java) - Nothing: a type with none field, used for
NULL
orvoid
3 Summary
Suppose T, T1, T2 ... Tn
are Declared Types, t, t1, t2 .. tn
are
their instances, we can get below super
chains:
Any <- Type <- DataType
Any <- Type <- UnionType
Any <- Type{T}
Any <- Type{Union(T1, T2)}
Any <- T
Any <- T1
Any <- T2
Any <- Tn
and issubtype
chains:
- all reversed
super
chains Type{T} <: DataType
Type{Union(T1,T2)} <: UnionType
(T1,T2) <: (Any, Any) <: Tuple
T1 <: Union(T1, T2) <: Top
and isa
chains:
- if
isa(m, M)
andM <: N
, thenisa(m, M)
t isa T isa Type{T}
t isa T isa DataType
(t1,t2) isa (T1, T2) isa (Type{T1}, Type{T2})
(t1,t2) isa (T1, T2) isa (DataType, DataType)
4 Some Demo Code
type T foo::Int bar::Float64 end type T1 qux::Any end immutable T2 r::Int g::Int b::Int end t = T(0, 1.0) t1 = T1(3) t2 = T2(1,2,3) # super @assert(is(super(T), Any)) @assert(is(super(T1), Any)) @assert(is(super(T2), Any)) @assert(is(super(Type{Union(T1, T2)}), Any)) @assert(is(super(Type), Any)) @assert(is(super(DataType), Type)) @assert(is(super(UnionType), Type)) @assert(is(super(Type{T}), Any)) # issubtype @assert(Type{T} <: DataType) @assert(Type{Union(T1, T2)} <: UnionType) @assert((T1,T2) <: (Any, Any) <: Tuple) @assert(None <: T1 <: Union(T1, T2) <: Top) # isa @assert(isa(t, T)) @assert(isa(t, Any)) @assert(isa(T, Type{T})) @assert(isa(T, DataType)) @assert(isa((t1, t2), (T1, T2))) @assert(isa((T1, T2), (Type{T1}, Type{T2}))) @assert(isa((T1, T2), (DataType, DataType)))
5 Discuss and Comment
Have few questions or feedback? Feel free to send me(zhuoql📧zoho.com) an email!