January 2020
Intermediate to advanced
532 pages
13h 31m
English
Abstract types can be enhanced in the same way that composite types can be parameterized. Let's continue with the preceding example. Suppose that we want to build an abstract type called Holding that keeps track of a P type that is used by its subtypes. We can code it as follows:
abstract type Holding{P} end
Then, every subtype of Holding{P} must also take a P type parameter. As an example, we can create two new types —StockHolding3{T,P} and CashHolding{P}:
struct StockHolding3{T, P} <: Holding{P}
stock::Stock quantity::T price::P marketvalue::Pendstruct CashHolding{P} <: Holding{P} currency::String amount::P marketvalue::Pend
We can examine how these types are related as follows:
Let's create a new ...
Read now
Unlock full access