My program precomputes some matrices, then operates on them. During the computation, it may turn out that some of the matrices are `Diagonal`

, etc. However, I do not know the structure ahead of time, and once pre-computed, the matrices are operated on iteratively. Currently I have a type that looks like:

```
struct MyModel
mats::Vector{AbstractMatrix{Float64}}
end
model = MyModel([Diagonal([1.0; 2.0]), [1.0 1.0; 1.0 1.0]])
```

and I have a function that looks like (simplified for brevity):

```
solve(m::MyModel) = m.mats[1] * m.mats[2]
```

The type can’t be inferred in this case, so the recommended recourse is to use a function barrier:

```
solve(m::MyModel) = solve(m.mats[1], m.mats[2])
solve(m1::AbstractMatrix, m2::AbstractMatrix) = m1 * m2
```

However, with this formulation of `MyModel`

, there is no way to run `solve`

on the top-level `model`

while getting a type-stable output.

Is this good enough? I’m wondering if there is a better way to set up `MyModel`

so that there are no abstract types in its definition, but I can still be fully expressive. What is the typical way to solve this problem? Would a `Union`

of the types I expect help?