Abstract, Concrete, and Parametric Types

In this lesson we’ll explore some of the more advanced features of Julia’s type system and how these tools allow you to write more expressive and higher-performance code. We’ll introduce how abstract and concrete types relate to each other in the type hierarchy as well as effective use of Julia’s multiple dispatch mechanism. We’ll also explore parametric types, which enable even more generic code without sacrificing performance.

Exploring the Type Hierarchy

Julia provides a subtyping mechanism with which you can describe relationships between types and place them in a tree-shaped hierarchy that represents different levels of generality and specificity. Figure 1-1 shows some commonly used types and their relationship to one another. Notice that this is a small fraction of the built-in types that exist, and external packages generally add their own types, as well. Types in this hierarchy can be said to have supertypes (sometimes referred to as parents in the tree) that are more general, and subtypes (or children) that are more specific. For instance the Real type represents numerical values that lie anywhere on the real line, and is a subtype of Number, which represents all numbers (including for example, complex numbers). Real has subtypes including AbstractFloat, Integer, and more depending on what packages are loaded.

acpt 01in01
Figure 1-1. A type ...

Get Learning Julia: Abstract, Concrete, and Parametric Types now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.