What is the diffence between abstract type and singleton type

Yes, that works too, and both approaches are viable. (You probably know that dispatching on pure types is quite common, such as with zeros(Int, 5)).

But using singleton instances has become a preferred idiom in many cases. See e.g. style guide: Style Guide · The Julia Language

You may also at some point decide that your singleton type should actually carry some parameter value inside it, to provide more information to the function you are calling, and then it is better if you originally used instance dispatch.

This thread may be of interest: Singleton types vs. instances as type parameters

2 Likes