# Specifying output container type based on input container

**URL:** https://discourse.julialang.org/t/specifying-output-container-type-based-on-input-container/96197
**Category:** General Usage
**Tags:** question
**Created:** [March 16, 2023, 4:51pm UTC](https://discourse.julialang.org/t/specifying-output-container-type-based-on-input-container/96197 "2023-03-16T16:51:40Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)
#### Post date: [March 16, 2023, 5:10pm UTC](https://discourse.julialang.org/t/specifying-output-container-type-based-on-input-container/96197/2 "2023-03-16T17:10:41Z")

</div>

Here’s a hacky attempt to inform the compiler about the container type (using [How to get the container type of a container?](https://discourse.julialang.org/t/how-to-get-the-container-type-of-a-container/20253)):

```julia
constructor_of(::Type{T}) where T =
    getfield(T.name.module, Symbol(T.name.name))

function f(x::A) where {T<:Real, N, A<:AbstractArray{T, N}}
   dropdims(sum(x, dims=(1,)), dims=(1,))::constructor_of(A){T,N-1}
end

```

where you would wrap the entire function block with `::constructor_of(A){T,N-1}`.

But surely there’s a way to do it directly in the function signature?

* * *

One other attempt:

```julia
function f(x::A)::(A.name.wrapper){T,N-1} where {T<:Real, N, A<:AbstractArray{T, N}}
   dropdims(sum(x, dims=(1,)), dims=(1,))
end

```

this feels illegal though. Not sure if `A.name.wrapper` is stable or not?

---

_[View the full topic](https://discourse.julialang.org/t/specifying-output-container-type-based-on-input-container/96197)._
