Book Image

Getting Started with Julia

By : Ivo Balbaert
Book Image

Getting Started with Julia

By: Ivo Balbaert

Overview of this book

Table of Contents (19 chapters)
Getting Started with Julia
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The Rationale for Julia
Index

The type hierarchy – subtypes and supertypes


(Follow along with the code in Chapter 6\type_hierarchy.jl.)

In Julia, every value has a type, for example, typeof(2) is Int64 (or Int32 on 32-bit systems). Julia has a lot of built-in types, in fact, a whole hierarchy starting from the type Any at the top. Every type in this structure also has a type, namely, DataType, so it is very consistent: typeof(Any), typeof(Int64), typeof(Complex{Int64}), and typeof(DataType) all return DataType. So, types in Julia are also objects; all concrete types, except tuple types, which are a tuple of the types of its arguments, are of type DataType.

This type hierarchy is like a tree; each type has one parent given by the super function:

  • super(Int64) returns Signed

  • super(Signed) returns Integer

  • super(Integer) returns Real

  • super(Real) returns Number

  • super(Number) returns Any

  • super(Any) returns Any

A type can have a lot of children or subtypes as follows:

  • subtypes(Integer) form 5-element Array{Any,1} that contains...