Unitful.jl | possibly mislabelled AbstractTypes, rare sametype() error | new user observations

The docs here are using “abstract type” in the common meaning of “a type that is not instantiable” i.e. something that’s not a concrete type:

julia> isconcretetype(Unitful.Length)
false

isabstracttype is very strict in what it checks for, as it says in its docs:

help?> isabstracttype
search: isabstracttype

  isabstracttype(T)

  Determine whether type T was declared as an abstract type (i.e. using the abstract keyword).

i.e. it only returns true for types that were declared specifically using the keyword abstract. Unitful.Length and others you tried happen to be Union types, so isabstracttype returns false for them. (Note that the manual section I’ve linked to also uses “abstract type” in the general meaning of it, saying: “A type union is a special abstract type”.)

When it comes to performance, however, what we care about is whether the type is concrete or not, as that has implications for how well the compiler can perform in generating fast code.

This usage is common in many parts of Julia, but still, it’s better to be clear and avoid confusion, especially in packages that are commonly used by non-developers. It seems best to just avoid using the phrase “abstract type” here, and instead change it to:

However, these are not concrete types. If performance is important, it may be better just to pick a concrete Quantity type.

This would prevent the confusion, while also avoiding a digression into what abstract types are and the behaviour of Base.isabstracttype.

1 Like