# Hi all. I have a function in which I create an array but the type of the array is

**URL:** <https://discourse.julialang.org/t/hi-all-i-have-a-function-in-which-i-create-an-array-but-the-type-of-the-array-is/56665>\
**Category:** General Usage\
**Created:** [March 7, 2021, 8:53am UTC](https://discourse.julialang.org/t/hi-all-i-have-a-function-in-which-i-create-an-array-but-the-type-of-the-array-is/56665 "2021-03-07T08:53:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 7, 2021, 8:53am UTC](https://discourse.julialang.org/t/hi-all-i-have-a-function-in-which-i-create-an-array-but-the-type-of-the-array-is/56665/1 "2021-03-07T08:53:29Z")

</div>

Hi all. I have a function in which I create an array but the type of the array is selected by the user meaning that it is passed as an argument something like:

```julia
function f(T)
    arr = Matrix{T}(undef,3,3)
    return arr
end

```

What is a correct type-stable way to do this? This is basically the function to load a bunch of data into named tuples with prespecified (I cannot use DataFrames).

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615107009496800?thread_ts=1615107009.496800&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 7, 2021, 8:44pm UTC](https://discourse.julialang.org/t/hi-all-i-have-a-function-in-which-i-create-an-array-but-the-type-of-the-array-is/56665/2 "2021-03-07T20:44:10Z")

</div>

Solution from Slack by Valentin:

probably

```julia
julia> function f(::Type{T}) where T    
           return Matrix{T}(undef, 3, 3)
       end

```

you have to remember that the type of `Float64` is `DataType` (like almost all types), so the compiler doesn’t know _which_ type it is. typing `::Type{T}` allows the compiler to know which type exactly it is
