Are `Int64` and `Float64` of the same type?

typeof(Int64) and typeof(Float64) are both DataType, but Int64 isa Type{Int64} while !(Float64 isa Type{Int64}) and I would expect nothing besides the type of a value be utilized in the isa opperation. So I ask, are Int64 and Float64 of the same type?

I ask in part to contextualize when Julia avoids specializing.

1 Like

They are two [very] distinct types. Here area couple of ways to see that they are of different natures.

julia> typeof(1) == typeof(1.0)
false

julia> Int64 <: Integer, Float64 <: Integer
(true, false)

julia> Int64 <: AbstractFloat, Float64 <: AbstractFloat
(false, true)

Both are subtypes of Real, that does not make them the same.

julia> isa(1, Real)
true
julia> isa(1.0, Real)
true
x = Int64
y = Float64

I’m not asking if x and y are the same value (x == y) I’m asking if x and y are of the same type

In the case below, z and w are of the same type. Same question but for x and y instead.

z = 1
w = 2
2 Likes

I think the answer is a clear: Well yes but actually no :sweat_smile: It depends on the context.

Both are technically instances of DataType as shown by typeof meaning they have the same data layout.

However in practice, one often wants to differentiate between types (e.g. for specialization) and so there is a another way you can view them: As singleton instances of Type{T}. I think this is really a special case for the isa operator and does not really follow the conventional rules. This is somewhat explained in the manual here:
https://docs.julialang.org/en/v1/manual/types/#man-typet-type

So in some technical sense there are instances of the same type, but in a type theory sense they are singleton instances of an appropriate Type{T} and both things hold simultaneously.

8 Likes

Thank you! This makes sense.

I guess Julia does have concrete subtyping. DataType is a concrete type, and Type{Int} is a subtype. The tricky/impossible thing to do efficiently and what Julia lacks is to be able to define a new concrete type that subtypes an existing concrete type and has a different data layout.

2 Likes

well this one is also tricky and does cause all sorts of complications in the type system

2 Likes