Block Array constructor in 0.7.0-rc2


Does anyone know why the following code returns true on julia 0.6.4 but false on 0.7.0-rc2? It looks like the way that array constructors are parsed may have changed, but I can’t find it in the Does anyone know how to overload the array constructor on 0.7 the same way I could on 0.6.4?

import Base: hcat, vcat, ==
mutable struct Foo{T,N}
Foo(x) = Foo(vcat(x))

hcat(a::Foo, b::Foo) = Foo(hcat(a.x,b.x))
vcat(a::Foo, b::Foo) = Foo(vcat(a.x,b.x))
==(a::Foo, b::Foo)   = a.x == b.x

[Foo(5) Foo(6); Foo(7) Foo(8)] == Foo([5 6; 7 8])
# true on 0.6.4
# false on 0.7.0-rc2

In particular, on 0.6.4:

julia> [Foo(5) Foo(6); Foo(7) Foo(8)]
Foo{Int64,2}([5 6; 7 8])

but on 0.7.0-rc2 I get:

julia> [Foo(5) Foo(6); Foo(7) Foo(8)]
2×2 Array{Foo{Int64,1},2}:
 Foo{Int64,1}([5])  Foo{Int64,1}([6])
 Foo{Int64,1}([7])  Foo{Int64,1}([8])


[Foo(5) Foo(6); Foo(7) Foo(8)] is lowered as hvcat in both versions, but v0.6 implements it using hcat and vcat, while in v0.7 there is a direct implementation.

You may have been relying on an implementation detail. Perhaps provide a method for hvcat, but it is slight abuse since that should return an <: AbstractMatrix.


Yeah I think that’s what was going on. I solved the problem by copying a version of the old hvcat fallback and explicitly specializing it so it only applies to my types.

More generally, I like the ability to overload the block array constructor, and have used it in TexTables.jl to make it easy to put tables together with the block array syntax. Since horizontal and vertical concatenation of tables makes a lot of sense in this context, I thought it was natural to overload the hcat and vcat operators. Maybe I shouldn’t abuse them in quite this way…