June 2019
Intermediate to advanced
218 pages
5h 19m
English
Type parameters are one of the most useful and powerful features of Julia's type system. This is the ability to use parameters when defining types (or functions), thereby defining a whole set of types, one for each value of the parameter. This is analogous to generic or template programming in other languages.
Type parameters are declared within curly braces. For the preceding Pixel type, if we wanted to store color as either an integer, a hexadecimal string, or as an structured RGB type, we would define its type to be parameterized. In this case, the unadorned name, Pixel, becomes an abstract type, and Pixel{Int64} or Pixel{String} are the concrete subtypes of Pixel:
struct Pixel{T} x::Int64 y::Int64 color::T end
Parameters ...
Read now
Unlock full access