Is there an isabstract(T) function where T is a DataType?

I wonder if there is a function that returns whether a type T is abstract or not. Any idea? I am trying to make a generator that returns all concrete types of a specific abstract type, and I need to check whether a certain type is abstract or not.

subtypes(T) is no good because it cannot differentiate between abstract types with no subtype (useful to have around for future support plans) and concrete types.

Base.isabstract

julia> isabstract
ERROR: UndefVarError: isabstract not defined

It’s not exported, which means that you have to explicitly do Base.isabstract as opposed to isabstract.

julia> Base.isabstract
ERROR: UndefVarError: isabstract not defined

Hmm… what version of Julia are you using? You should upgrade to the latest 0.6 release candidate.

I am using 0.5. Ok if I have to upgrade, then I will just manually enumerate them instead!

It’s in Compat

julia> using Compat

julia> isabstract
ERROR: UndefVarError: isabstract not defined

julia> Compat.isabstract
ERROR: UndefVarError: isabstract not defined

https://github.com/JuliaLang/Compat.jl#new-functions-macros-and-methods

Ic. Thanks alot!

julia> Compat.TypeUtils.isabstract
isabstract (generic function with 3 methods)

julia> Compat.TypeUtils.isabstract(Int)
false

julia> Compat.TypeUtils.isabstract(Integer)
true

I was just searching for an isabstract function and also found Base.isabstract. However, I noticed Base.isabstract(Complex) == false which seems wrong to me.

But someone on Slack pointed out that there is isleaftype. I thought it might be useful to mention it here.

From v0.7:

julia> isleaftype(Array)
┌ Warning: `isleaftype` is deprecated, use `isconcrete` instead.
│   caller = top-level scope
└ @ Core :0
false

Even better!

why? it is not an abstract type.

It is a UnionAll type, which is NOT a concrete type. But I don’t know if not being concrete is the definition of an abstract type :thinking:

Abstract type = abstract type

1 Like

But it isn’t. See the documentation for isconcrete:

Determine whether T is a concrete type, meaning it can have direct instances (values x such that typeof(x) === T).

I agree that the terminology is not the most intuitive. Similarly to topology, where a set not being open does not mean it is closed.

1 Like

As this shows up as a top result in my search, for anyone else looking for this these days:

the latest function that checks whether a type can have instances is isconcretetype

Related functions are isabstracttype, issingletontype.

3 Likes