liveBook · Manning

Primitive data type

As explained in Julia as a Second Language

A primitive type is a type represented directly by a language implementation rather than as a collection of user-defined fields.

A primitive data type is a concrete type that represents a single value rather than a collection of fields. Integers, characters, and floating-point numbers are primitive types in Julia; they cannot be broken down into smaller parts. section 7.1 section 7.3.1

The type controls what an object can do. For example, a Bool can participate in an if statement or while loop, whereas a floating-point value cannot be used directly as a Boolean condition. section 7.0

Primitive types become useful when contrasted with other kinds of Julia types:

  • A composite type contains zero or more fields and can combine primitive values, such as a String containing multiple Char values. section 7.1 section 7.5
  • An abstract type cannot contain fields or hold a value; it organizes type hierarchies rather than representing an individual data value. section 7.3.1
  • Primitive types are concrete, so they occupy the concrete leaves of Julia's type hierarchy and can be used to create values. section 7.3.1 section 7.5

Checking primitive types in the REPL

julia> isprimitivetype(Int8) true julia> isprimitivetype(Char) true julia> isprimitivetype(String) false The predicate identifies Int8 and Char as primitive types, while String is composite because it consists of multiple characters. section 7.1

julia> isprimitivetype(Int8)
true

julia> isprimitivetype(Char)
true

julia> isprimitivetype(String)
false

Inspect the compact REPL comparison of Int8, Char, and String to see primitive and composite classification directly. section 7.1

How Julia as a Second Language covers it

How deep it goes
Defines primitive types, names their common examples, checks them with isprimitivetype, and stops short of implementation-level representation details.
Examples
Uses integers, characters, floating-point numbers, strings, and an isprimitivetype REPL check as concrete examples.
What you can do after
Evaluate whether a Julia type is primitive and distinguish its single value from a composite type's fields.
How it connects
Connects primitive types to concrete types, composite types, abstract types, and Julia's type hierarchy.

Also explained in

Compare how 6 books explain primitive data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.