# A precise definition of what it means to be an instance of an abstract type

**URL:** <https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 16, 2021, 7:45am UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270 "2021-03-16T07:45:56Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [March 16, 2021, 12:00pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/21 "2021-03-16T12:00:29Z")

</div>

> [@path-doc](#):
>
> (Btw, someone else somewhere was saying that `Ptr` is definitely abstract.) So according to you, parametric supertypes are neither concrete, nor abstract.

Did you watch the video that has been linked to you multiple times? It explains things quite clearly.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 16, 2021, 12:02pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/22 "2021-03-16T12:02:20Z")

</div>

> [@path-doc](#):
>
> So according to you, parametric supertypes are neither concrete, nor abstract.

It’s a `UnionAll` 🙂 Also, you can have parametric abstract types (e.g. `AbstractArray{T,N}`), so `UnionAll` is orthogonal to being abstract or concrete.

> [@path-doc](#):
>
> Though their subtypes are all concrete?

Not necessarily: `Array{Float64} <: Array`, but it isn’t concrete, it’s another `UnionAll`: you need to specify _all_ parameters in order to get a concrete type.

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 12:57pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/23 "2021-03-16T12:57:44Z")

</div>

Thanks, please explain meaning of “orthogonal”. Are you saying it is independent (in the logical sense) of being abstract or concrete?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 16, 2021, 12:59pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/24 "2021-03-16T12:59:26Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 1:00pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/25 "2021-03-16T13:00:30Z")

</div>

To be honest I come from a fairly pure school of mathematics, so I don’t see why I should look to a video for a definition. But given your recommendation, I will. Yes, I have been into the manual, but I didn’t see anything about how the type space is partitioned. A nice diagram would do it.

---

<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:** [March 16, 2021, 1:07pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/26 "2021-03-16T13:07:02Z")

</div>

> [@path-doc](#):
>
> To be honest I come from a fairly pure school of mathematics, so I don’t see why I should look to a video for a definition

It seems you want to learn about the type system of Julia. The video is about the Julia type system from the creator of Julia. How can you not want to watch it??

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 1:09pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/27 "2021-03-16T13:09:25Z")

</div>

I am looking for formal definitions. Can you point to a formal definition of how types are partitioned?

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [March 16, 2021, 1:14pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/28 "2021-03-16T13:14:15Z")

</div>

Here you go: [https://benchung.github.io/papers/jlsub.pdf](https://benchung.github.io/papers/jlsub.pdf)

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 1:15pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/29 "2021-03-16T13:15:55Z")

</div>

Thanks, yes, that is a very useful reference. I have been reading that for a few days now.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 16, 2021, 1:24pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/30 "2021-03-16T13:24:39Z")

</div>

In case it isn’t clear enough, there hasn’t been a rigorous formal description of the type system _before_ its implementation. Some researchers, like those in the paper linked above, have studied it afterwards. If you’re looking for an original complete formalisation of the type system you won’t simply find it anywhere, it doesn’t exist

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 1:39pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/31 "2021-03-16T13:39:40Z")

</div>

I appreciate that. But then can you please add some more flesh/structure to your previous statements. Can you prove that `Ptr` is neither Concrete, nor Abstract? Or would you point me to a video or the manual?

_(Sorry, must have been tired last night.)  
 **Correct version.**  
Let’s agree that abstract types are defined as precisely those that cannot be instantiated. That is, they only exist as nodes on the graph of types (this is literally from the manual). Moreover, let’s work with `Array` instead of `Ptr`._

_You see, I would say that one way to tell that `Array` is abstract is that it can’t be instantiated in the sense that, unlike concrete types, there will never be an instance of an object `x` such that `typeof(x) = Array`. Since the parametric type `Array` can’t be instantiated in this sense, it only exists as a node on the graph and it is formally abstract._

_Now concrete and abstract are complementary properties, thus `Array` is not concrete by virtue of the fact that it is abstract._

_Next let’s prove that `Array{Float64} is a concrete type:_

```nohighlight
julia> x = [1.0]
1-element Array{Float64,1}:
 1.0

julia> typeof(x) == Array{Float64,1}
true

```

~~This is how I like to operate. I don’t trust videos or manuals. I barely even trust my own definition. Though I have to say it has held its own in this conversation.~~

So, assuming `Ptr` and `Array` similar in this respect, I deduce that `Ptr` is abstract (contrary to yesterday’s conclusions). You are completely right about the parametric instances of `Ptr` and `Array`: they are indeed concrete.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 16, 2021, 1:52pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/32 "2021-03-16T13:52:33Z")

</div>

> [@path-doc](#):
>
> Can you prove that `Ptr` is neither Concrete, nor Abstract? Or would you point me to a video or the manual?

`Ptr` is a shortcut for `Ptr{T} where {T}` and it’s the set of all `Ptr{T}` over all `T`. It isn’t abstract in the sense that you can’t define a new type `X` such that `X <: Ptr{T}`. It isn’t concrete in the sense that you need to concretely specify `T` in order to have a concrete type that can actually be instantiated. Again, `Ptr` isn’t _a_ type, it’s a set of types.

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 2:08pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/33 "2021-03-16T14:08:15Z")

</div>

The above like applies to everything except your last sentence.

> [@giordano](#):
>
> you should think of types as the set of values they can take, and `<:` is the subset relationship.

Because then every type is a set.

I think am looking for defining properties of objects that are neither concrete, nor abstract.

I am now sure that parametric supertypes lie in the complement of both concrete and abstract. In contrast, other parametric (sub)types such as `Ptr{Float64}` are concrete because they can have instances eg pointers themselves.

Thanks @giordano, you’re very helpful.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [March 16, 2021, 2:11pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/34 "2021-03-16T14:11:57Z")

</div>

> [@path-doc](#):
>
> Because then every type is a set.

That’s correct: a type is the set of all values it can hold. A `UnionAll` is a set of types, so the union of multiple sets.

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 16, 2021, 2:17pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/35 "2021-03-16T14:17:26Z")

</div>

But then it doesn’t help me: it’s a property of everything. I am looking to organise my mental map of the type space. (I mean numbers like 1, 2, … can also be viewed sets, this is what we do when we conduct well-ordered sets.)

Thanks again, and bye for now. It’s past midnight where I live.

---

<div class="post-metadata">

**Author:** ![path-doc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/path-doc/32/19183_2.png) [@path-doc](https://discourse.julialang.org/u/path-doc)\
**Post date:** [March 17, 2021, 12:41pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/36 "2021-03-17T12:41:13Z")

</div>

**Definition** : Object x is an _instance_ of the abstract type y if, ~~and only if~~ ,

1. the concrete type t\_x of x and the value v\_y of y satisfy t\_x\<:v\_y, or
2. y is a singleton type and x is its instance (which can be verified using `isa`)
3. …  
[What is difference between Type{T} and T - #58 by path-doc](https://discourse.julialang.org/t/what-is-difference-between-type-t-and-t/19325/58)

---

<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:** [March 17, 2021, 1:58pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/37 "2021-03-17T13:58:49Z")

</div>

> [@path-doc](#):
>
> I am looking to organise my mental map of the type space. (I mean numbers like 1, 2, … can also be viewed sets, this is what we do when we conduct well-ordered sets.)

With respect, I think that approaching the _whole_ of Julia’s type system with a very formal/mathematical mindset is unlikely to be helpful in using Julia.

The basic intuitive building blocks are (ignore `Type` and types as values for now):

1. values have a type, which you can query with `typeof`,
2. these types are organized into a tree, with `<:`,
3. types have parameters.

Now the complications: types themselves are first-class objects, so you can consider them values, with `typeof(SomeType) == DataType`. This is not super-helpful for dispatch, so `Type{T}` was introduced as a _selector_ — the [updated manual](https://docs.julialang.org/en/v1.6-dev/manual/types/#man-typet-type) makes this more clear. But seeing a `Type` outside a method signature is code smell, and integrating `Type` and `DataType` into your mental map of Julia types is just a recipe for a headache.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [March 17, 2021, 2:38pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/38 "2021-03-17T14:38:09Z")

</div>

> [@Tamas\_Papp](#):
>
> But seeing a `Type` outside a method signature is code smell

What about instantiating a parametric type, such as Array{Float64,1}? Is that also a code smell? I ask because I’ve seen many discussions of performance here mentioning avoiding containers that might infer the element type as an abstract type, particularly Any.

---

<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:** [March 17, 2021, 2:44pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/39 "2021-03-17T14:44:25Z")

</div>

> [@Jeff\_Emanuel](#):
>
> What about instantiating a parametric type, such as Array{Float64,1}? Is that also a code smell?

Nope, that may be fine, especially if you do type calculations, or need the type repeatedly.

But I would avoid the term “instantiate”: in idiomatic code, that will be something the compiler just gets rid of. It is no more “instantiated” than `1` is.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [March 17, 2021, 2:49pm UTC](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270/40 "2021-03-17T14:49:40Z")

</div>

Maybe construct is the right word and I’m misapplying vocabulary from OOP languages.  
Say I want to create an instance of a Dict and not have it infer Anys. I have been writing, for example, `d = Dict{String,Float64}()`. Would that be proper?

And I apologize for the digression from the original topic.

[Previous page](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270.md?page=1)

[Next page](https://discourse.julialang.org/t/a-precise-definition-of-what-it-means-to-be-an-instance-of-an-abstract-type/57270.md?page=3)
