Usage of "empty" structs

It’s often used for multiple dispatch. Example:

abstract type RangeStepStyle end

struct RangeStepRegular <: RangeStepStyle end
struct RangeStepIrregular <: RangeStepStyle end

range_step(n, ::Type{RangeStepRegular}) = println("regular step: $n")
range_step(n, ::Type{RangeStepIrregular}) = println("not a normal step: $n")

range_step(3, RangeStepRegular)
range_step(6, RangeStepIrregular)

Result:

regular step: 3
not a normal step: 6
2 Likes