On Wednesday, September 30, 2015 at 2:51:46 PM UTC-4, Christoph Ortner
wrote:
>
> I, on the other hand, don't understand the obsession with abstraction.
>
> Also, by your argument the following should all be special types rather
> than box-standard arrays.
>
> julia> typeof(ones(10))
> Array{Float64,1}
>
> julia> typeof(zeros(10))
> Array{Float64,1}
>
Arrays of ones and (especially) zeros are commonly used as a starting point
for something that is written to, so it would be much less useful for these
to return read-only objects.
More generally, returning an Array is much easier to implement (less code),
so Base is only going to return special objects in cases that are extremely
widely used to allocate what would otherwise be very large objects, like
linspace.
julia> typeof(eye(10))
> Array{Float64,2}
>
Actually, Julia does have a special "I" object and corresponding type for
operations with the identity matrix. e.g. A + 3I is more efficient than A
+ 3*eye(A), because in A+3I only the diagonals have to be added.