A concrete type describes values you can create directly. In Julia, an abstract type instead groups related types in a hierarchy: you cannot instantiate it. Concrete types sit at the leaves of that hierarchy, because Julia does not allow a concrete type to subtype another concrete type. section 7.3.1 section 7.5
For a battle simulator, an abstract Warrior can group concrete Archer, Pikeman, and Knight types. Each concrete type defines its own fields: an Archer has a name, health, and arrows, while a Knight has a mounted state. Shared fields such as name and health are a convention here; Julia does not enforce them through the abstract type. section 7.3.1
Listing 7.5 Definition of types in battle simulator
abstract type Warrior end #1
mutable struct Archer <: Warrior #2
name::String
health::Int
arrows::Int
end
mutable struct Pikeman <: Warrior
name::String
health::Int
end
mutable struct Knight <: Warrior
name::String
health::Int
mounted::Bool #3
end
Define Warrior as an abstract type and its three concrete subtypes as mutable structs. The mutable keyword allows their fields to change at runtime. section 7.3.1 section 7.5
julia> robin = Archer("Robin Hood", 34, 24)
Archer("Robin Hood", 34, 24)
julia> Warrior()
ERROR: MethodError: no constructors have been defined for Warrior
Constructing an Archer creates a value; attempting to construct a Warrior fails because Warrior is abstract. section 7.3.1
A composite type is a concrete type made from zero or more fields; a primitive type is a concrete type with a single value. Use typeof on an object to discover its type, and supertype or subtypes to explore the hierarchy. section 7.3.1 section 7.5
Abstract types and multiple dispatch make the concrete types useful together. A battle! method accepting two Warriors can receive an Archer and a Knight; the actual argument types determine which attack! method runs. section 8.9 section 7.4.2



