Default constructor for "triangular" types?


#1

Consider this struct type (defined “triangular” with some abuse of language):

julia> struct Foo{T, N, A<:AbstractArray{T, N}} <: AbstractArray{T, N}
           a::A
       end

It seems that the default constructor does not infer the type

julia> Foo([1, 2, 3])
ERROR: MethodError: Cannot `convert` an object of type Array{Int64,1} to an object of type Foo
This may have arisen from a call to the constructor Foo(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] Foo(::Array{Int64,1}) at ./sysimg.jl:24

# define this outer constructor
julia> Foo(a::AbstractArray{T, N}) where {T, N} = Foo{T, N, typeof(a)}(a)
Foo

# then OK.
julia> Foo([1, 2, 3]);

This seems not to be documented (e.g. by a quick look in the constructors section). Is the outer constructor really needed or I am missing something?