# Default constructor for "triangular" types?

**URL:** <https://discourse.julialang.org/t/default-constructor-for-triangular-types/5667>\
**Category:** General Usage\
**Created:** [August 31, 2017, 10:39pm UTC](https://discourse.julialang.org/t/default-constructor-for-triangular-types/5667 "2017-08-31T22:39:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gasagna](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gasagna/32/1275_2.png) [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Post date:** [August 31, 2017, 10:39pm UTC](https://discourse.julialang.org/t/default-constructor-for-triangular-types/5667/1 "2017-08-31T22:39:14Z")

</div>

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

```julia
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
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?
