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

(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.

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


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

1 Like

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.


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


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.

For recording,

Here is a related discussion

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.