# Dispatch on parametric type

**URL:** <https://discourse.julialang.org/t/dispatch-on-parametric-type/37978>\
**Category:** General Usage\
**Created:** [April 21, 2020, 6:06pm UTC](https://discourse.julialang.org/t/dispatch-on-parametric-type/37978 "2020-04-21T18:06:13Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![helgee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgee/32/2022_2.png) [@helgee](https://discourse.julialang.org/u/helgee)\
**Post date:** [April 22, 2020, 4:38am UTC](https://discourse.julialang.org/t/dispatch-on-parametric-type/37978/8 "2020-04-22T04:38:26Z")

</div>

We recently had a similar discussion here:

> [@Abstract type versus singleton struct](https://discourse.julialang.org/t/abstract-type-versus-singleton-struct/36356):
>
> This question originates from a discussion in [Use relative transformations by helgee · Pull Request #48 · JuliaAstro/AstroTime.jl · GitHub](https://github.com/JuliaAstro/AstroTime.jl/pull/48) The AstroTime library provides a way to store and operate on Epochs in different timescales. Each timescale has its own type: MWE with 2 timescales TT and TDB: abstract type TimeScale end struct ConcreteTDBScale \<: TimeScale end const TDB = ConcreteTDBScale() struct ConcreteTTScale \<: TimeScale end const TT = ConcreteTTScale() struct CEpoch{S\<:TimeScale}…

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.

```julia
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

```

---

_[View the full topic](https://discourse.julialang.org/t/dispatch-on-parametric-type/37978)._
