1+ abstract type AbstractCablePart end
2+
3+ struct ConductorPart{L, T, S <: AbstractShape{L, T} } <: AbstractCablePart
4+ tag:: Symbol
5+ shape:: S
6+ material:: Material{T}
7+ end
8+
9+ function ConductorPart (
10+ tag:: Symbol ,
11+ shape:: AbstractShape{L, T_shape} ,
12+ mat:: Material{T_mat} ,
13+ ) where {L, T_shape, T_mat}
14+ # 1. Ask the compiler what the safest common type is.
15+ T_common = promote_type (T_shape, T_mat)
16+
17+ # 2. Let native dispatch handle the translation.
18+ shape_promoted = convert (AbstractShape{L, T_common}, shape)
19+ mat_promoted = convert (Material{T_common}, mat)
20+
21+ return ConductorPart {L, T_common, typeof(shape_promoted)} (
22+ tag,
23+ shape_promoted,
24+ mat_promoted,
25+ )
26+ end
27+
28+ struct InsulatorPart{L, T, S <: AbstractShape{L, T} } <: AbstractCablePart
29+ tag:: Symbol
30+ shape:: S
31+ material:: Material{T}
32+ end
33+
34+ function InsulatorPart (
35+ tag:: Symbol ,
36+ shape:: AbstractShape{L, T_shape} ,
37+ mat:: Material{T_mat} ,
38+ ) where {L, T_shape, T_mat}
39+ # 1. Ask the compiler what the safest common type is.
40+ T_common = promote_type (T_shape, T_mat)
41+
42+ # 2. Let native dispatch handle the translation.
43+ shape_promoted = convert (AbstractShape{L, T_common}, shape)
44+ mat_promoted = convert (Material{T_common}, mat)
45+
46+ return InsulatorPart {L, T_common, typeof(shape_promoted)} (
47+ tag,
48+ shape_promoted,
49+ mat_promoted,
50+ )
51+ end
0 commit comments