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

**URL:** <https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165>\
**Category:** General Usage\
**Created:** [June 8, 2017, 5:33pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165 "2017-06-08T17:33:17Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 5:33pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/1 "2017-06-08T17:33:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 8, 2017, 5:59pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/2 "2017-06-08T17:59:28Z")

</div>

`Base.isabstract`

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 6:17pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/3 "2017-06-08T18:17:59Z")

</div>

```julia
julia> isabstract
ERROR: UndefVarError: isabstract not defined

```

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [June 8, 2017, 6:23pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/4 "2017-06-08T18:23:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 6:25pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/5 "2017-06-08T18:25:09Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [June 8, 2017, 6:27pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/6 "2017-06-08T18:27:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 6:28pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/7 "2017-06-08T18:28:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 8, 2017, 6:57pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/8 "2017-06-08T18:57:54Z")

</div>

It’s in `Compat`

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 7:09pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/9 "2017-06-08T19:09:10Z")

</div>

```julia
julia> using Compat

julia> isabstract
ERROR: UndefVarError: isabstract not defined

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

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 8, 2017, 7:37pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/10 "2017-06-08T19:37:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [June 8, 2017, 7:46pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/11 "2017-06-08T19:46:19Z")

</div>

Ic. Thanks alot!

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

julia> Compat.TypeUtils.isabstract(Int)
false

julia> Compat.TypeUtils.isabstract(Integer)
true

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [January 7, 2018, 12:22pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/12 "2018-01-07T12:22:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [January 7, 2018, 12:38pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/13 "2018-01-07T12:38:53Z")

</div>

From v0.7:

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

```

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [January 7, 2018, 12:45pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/14 "2018-01-07T12:45:39Z")

</div>

Even better!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 7, 2018, 1:04pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/15 "2018-01-07T13:04:50Z")

</div>

> [@carstenbauer](#):
>
> `Base.isabstract(Complex) == false` which seems wrong to me

why? it is [not an abstract type](https://github.com/JuliaLang/julia/blob/abb2061662f9f8267c5474b35c9eb18c95f82cf3/base/complex.jl#L11-L14).

---

<div class="post-metadata">

**Author:** ![favba](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/favba/32/2735_2.png) [@favba](https://discourse.julialang.org/u/favba)\
**Post date:** [January 7, 2018, 3:32pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/16 "2018-01-07T15:32:49Z")

</div>

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 🤔

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 7, 2018, 3:38pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/17 "2018-01-07T15:38:36Z")

</div>

Abstract type = `abstract type`

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 7, 2018, 3:51pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/18 "2018-01-07T15:51:17Z")

</div>

> [@favba](#):
>
> But I don’t know if not being concrete is the definition of an abstract type

But it isn’t. See the [documentation for `isconcrete`](https://docs.julialang.org/en/latest/stdlib/base/#Base.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.

---

<div class="post-metadata">

**Author:** ![3ArnjN](https://avatars.discourse-cdn.com/v4/letter/3/ba8739/32.png) [@3ArnjN](https://discourse.julialang.org/u/3ArnjN)\
**Post date:** [October 13, 2022, 2:49pm UTC](https://discourse.julialang.org/t/is-there-an-isabstract-t-function-where-t-is-a-datatype/4165/19 "2022-10-13T14:49:06Z")

</div>

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`](https://docs.julialang.org/en/v1/base/base/#Base.isconcretetype)

Related functions are [`isabstracttype`](https://docs.julialang.org/en/v1/base/base/#Base.isabstracttype), [`issingletontype`](https://docs.julialang.org/en/v1/base/base/#Base.issingletontype).
