# What problems will one have, if \`Real\` was made a subtype of \`Complex\`?

**URL:** https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662
**Category:** New to Julia
**Tags:** question, type
**Created:** [July 23, 2019, 3:01am UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662 "2019-07-23T03:01:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![tianrluo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tianrluo/32/7629_2.png) [@tianrluo](https://discourse.julialang.org/u/tianrluo)
#### Post date: [July 23, 2019, 3:01am UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/1 "2019-07-23T03:01:29Z")

</div>

(New to Julia, and type theory/system.)

(Original question above this line)

* * *

@Tamas_Papp @Per Thanks for answering!

Basically, the story was I had a function similar to `f(a::Complex) = a`, and expected it to accept `Int64` and return `complex(a)`.  
Then apparently I got bewildered and realized `Int64<:Real`, but not `Int64<:Complex`.  
Then as a frequent Matlab user, who’s used to see complex function handles real inputs indifferently, I started wondering why this type relation was designed intentional in julia.

I also learnt from other sources `subtype`/`supertype` relation is akin to inheritance, rather than a mathematical field extension.

---

<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: [July 23, 2019, 6:00am UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/2 "2019-07-23T06:00:02Z")

</div>

I don’t quite understand what you are asking, since `Complex{T}` is a _concrete_ type, and as such cannot have subtypes. I would recommend reading

[https://docs.julialang.org/en/v1/manual/types/](https://docs.julialang.org/en/v1/manual/types/)

and then using Julia for a while so that you gain an understanding of types in practice.

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [July 23, 2019, 6:07am UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/3 "2019-07-23T06:07:58Z")

</div>

`Complex` is not a `DataType`. It is a `UnionAll`. A shorthand for `Complex{T} where T`, and making `Real <: Complex{T} where T` doesn’t make sense, because it leaves out the `T`.

On the other hand, something `Real{T} <: Complex{T}` might make sense, but Julia does not allow subtyping non-`abstract` (i.e. concrete) types, probably for very good reasons. So you’d have to create an `AbstractComplex` type, which is what `Number` is.

---

<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: [July 23, 2019, 1:09pm UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/4 "2019-07-23T13:09:04Z")

</div>

Please note that removing the question from your original post and replacing it with your reply is very confusing to future readers.

---

<div class="post-metadata">

### Author: ![tianrluo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tianrluo/32/7629_2.png) [@tianrluo](https://discourse.julialang.org/u/tianrluo)
#### Post date: [July 23, 2019, 1:10pm UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/5 "2019-07-23T13:10:40Z")

</div>

Oh, sorry about that, I didn’t remove the question.  
The original post only contains what’s in the parentheses.  
I’ll separate them for clarification.

---

<div class="post-metadata">

### Author: ![tianrluo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tianrluo/32/7629_2.png) [@tianrluo](https://discourse.julialang.org/u/tianrluo)
#### Post date: [July 23, 2019, 6:09pm UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/6 "2019-07-23T18:09:32Z")

</div>

For recording,  
[https://github.com/JuliaLang/julia/issues/8142](https://github.com/JuliaLang/julia/issues/8142)  
Here is a related discussion

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [July 23, 2019, 6:10pm UTC](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662/7 "2019-07-23T18:10:30Z")

</div>

The actual implementation of `Complex` (being non-abstract) is really just a red herring to this question. Sure, you can’t subtype a non-abstract type, but if we really wanted to express the mathematical truth that the Reals are embedded in the Complex universe, we totally could have structured the type tree with an AbstractComplex supertype. The simple answer is that these type trees aren’t describing mathematical truths but rather they’re practical realizations that we find useful.

[https://github.com/JuliaLang/julia/issues/15086#issuecomment-185011848](https://github.com/JuliaLang/julia/issues/15086#issuecomment-185011848)
