It is, and eldee didn’t mean that. They meant that you tried to insert an entire 10-element Vector{Int}
as 1 element of another Vector{Int}
, which is not possible because Vector{Int}
can only have elements of Int
. You would need a Vector{Vector{Int}}
to do that exact thing, though there are likely better ways to cache each sequence of integers for each line of text, depending on how file.txt is structured.
There is no separate 1
and 0
there, it really is 10
fitting in one element (we don’t call it cell, but that’s what it is). If you’re wondering why 10
is 2 characters taking twice the space of the smaller integers, it’s just the monospaced printout. A character has nothing to do with the size of the element, and monospacing will never squeeze multiple characters into the space of one.
mbauman is talking about types, specifically concrete types that can have instances. For example, "hello"
and "world"
are instances of the concrete type String
. For this question, we need to consider 2 purposes of a concrete type:
-
The computer doesn’t directly store the instances
"hello"
,7
, or3.14
. There are physical media storing binary data, which we can call 1s and 0s. A concrete type specifies how a segment or multiple segments of binary data represents instances, and users usually don’t need to care about the specifics. -
A type helps specify what functions/methods can work on its instances. Users do have to know what types can do, and convert between types to do what they want.
As mbauman said, the String
type can represent integers, and its binary data and thus the integer can get as large as your memory allows. The problem is it is not a type suited for arithmetic, so there aren’t methods implemented for it, e.g. "1" + "1"
will fail. There are however many numeric types like Int8
, Int16
, Int32
, Int64
, etc that do support arithmetic, and parse
can be used to convert String
s to them, as demonstrated earlier. Numeric types also often have fixed sizes of binary data, so they can support the function typemax
, which tells you a type’s maximum representable value:
julia> typemax(Int64)
9223372036854775807
If your array’s element type happens to be one of these types, you can extract it with eltype
and pass it to typemax
:
julia> typemax(eltype(fill(0, 10)))
9223372036854775807
Note that Int
(and UInt
) isn’t the same data type everywhere; it aliases Int32
on 32-bit systems but Int64
on 64-bit systems, because of the differences of how they work. As a user, you don’t have to care about all the details, but you should use Int
for array dimensions/indexing and recognize that the parser will treat integers in text as Int
(so validate and convert values if you need). You can find out which system via Julia by evaluating Int
in the REPL and seeing the printout, or Sys.WORD_SIZE
encodes it directly.