# Parametric Type for Uninitialized/Undef Objects

**URL:** <https://discourse.julialang.org/t/parametric-type-for-uninitialized-undef-objects/91543>\
**Category:** General Usage\
**Tags:** question, parametric-types, ref, undef, undefinitializer\
**Created:** [December 12, 2022, 6:06am UTC](https://discourse.julialang.org/t/parametric-type-for-uninitialized-undef-objects/91543 "2022-12-12T06:06:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [December 12, 2022, 6:06am UTC](https://discourse.julialang.org/t/parametric-type-for-uninitialized-undef-objects/91543/1 "2022-12-12T06:06:47Z")

</div>

I’ve learned that you can create type-stable references to uninitialized objects like so:

```julia
julia> struct Foo{A} a::A end

julia> x = Ref{Foo{Int}}()
Base.RefValue{Foo{Int64}}(Foo{Int64}(1847082903376))

julia> x[] = Foo(1)
Foo{Int64}(1)

julia> y = Array{Foo{Int}}(undef)
0-dimensional Array{Foo{Int64}, 0}:
Foo{Int64}(140703227812064)

julia> y[] = Foo(1)
Foo{Int64}(1)

```

I have a function which receives a wide range of possible argument types (including types).

I’d like a way to communicate to this function the _type_ of an uninitialized object to make a reference to, in a way that simultaneously communicates that a reference to an uninitialized object should be created (i.e., when simply sending normal types I want it not to behave this way), and without forcing the other arguments to also be uninitialized.

I’m thinking maybe something similar to `Val(Foo{Int})`, but not using `Val` because that usually means something different. Something along the lines of maybe `Undef(Foo{Int})`, if it worked like `Undef(Foo{Int}) === Undef{Foo{Int}}()`?

I imagine if `Ref`’s constructor had a type-specialization for it, such a thing could work like this:

```julia
#= simulated =#
julia> Ref(Undef(Foo{Int}))
Base.RefValue{Foo{Int64}}(Foo{Int64}(1847085789424))

```

or that you could initialize an array like so:

```julia
#= simulated =#
julia> Matrix(Undef(Int), 4, 4)
4×4 Matrix{Int64}:
 1847054304048 1847054304816 1847054305072 1847054306160
 1847054304624 1847054304880 1847054305328 1847054306224
 1847054304688 1847054304944 1847054306032 1847054306288
 1847054304752 1847054305008 1847054306096 1847054306352

```

Is there any existing type that’s suitable for this?
