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

Types


Julia's type system is unique. Julia behaves as a dynamically-typed language (such as Python for instance) most of the time. This means that a variable bound to an integer at one point might later be bound to a string. For example, consider the following:

julia> x = 10
10
julia> x = "hello"
"hello"

However, one can, optionally, add type information to a variable. This causes the variable to only accept values that match that specific type. This is done through a type annotation. For instance, declaring x::ASCIIString implies that only strings can be bound to x; in general, it looks like var::TypeName. These are used most often to qualify the arguments a function can take. The extra type information is useful for documenting the code, and often allows the JIT compiler to generate better optimized native code. It also allows the development environments to give more support, and code tools such as a linter that can check your code for possible wrong type use.

Here is an example...