Dispatch on parametric type

We recently had a similar discussion here:

The TL;DR is that it is better to use explicit fields with singleton instances of structs instead of abstract types for dispatch because it composes better, is extendable, and easier to understand, e.g.

abstract type MyType end
struct AType <: MyType end
const A = AType()
struct BType <: MyType end
const B = BType()

struct MyStruct1{MT<:MyType,T}
    field::MT
    val1::T
    val2::T
    # ...
end
3 Likes