# Is it possible to get an incompletely specified type?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331>\
**Category:** General Usage\
**Created:** [February 17, 2024, 1:57am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331 "2024-02-17T01:57:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 17, 2024, 1:57am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/1 "2024-02-17T01:57:35Z")

</div>

```julia
julia> struct A{T}; a::T; end

julia> a1 = A(1)
A{Int64}(1)

julia> a2 = A(1.0)
A{Float64}(1.00000e+00)

julia> typeof(a1) === typeof(a2)
false

```

Yet, both `a1` and `a2` are “of type `A`”. Is it possible to test that?

---

<div class="post-metadata">

**Author:** ![Tortar](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@Tortar](https://discourse.julialang.org/u/Tortar)\
**Post date:** [February 17, 2024, 2:22am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/3 "2024-02-17T02:22:12Z")

</div>

Ok, see [printing - Get simple name of type in Julia? - Stack Overflow](https://stackoverflow.com/questions/70043313/get-simple-name-of-type-in-julia).

The solution is to use

```julia
julia> name(::Type{T}) where {T} = (isempty(T.parameters) ? T : T.name.wrapper)

julia> name(typeof(a1)) === name(typeof(a2))
true

```

---

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [February 17, 2024, 3:29am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/4 "2024-02-17T03:29:00Z")

</div>

Depending on your underlying use case, the [`typejoin`](https://docs.julialang.org/en/v1/base/base/#Base.typejoin) function may be of interest, which returns “the closest common ancestor of types `T` and `S` , i.e. the narrowest type from which they both inherit”, in this case `A`.

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 17, 2024, 8:51am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/5 "2024-02-17T08:51:35Z")

</div>

> [@PetrKryslUCSD](#):
>
> both `a1` and `a2` are “of type `A`”. Is it possible to test that?

I guess you’re not simply looking for `a1 isa A && a2 isa A` ? 🙂

Another possibility in this case I think would be `nameof(typeof(a1)) == nameof(typeof(a2))`.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 17, 2024, 9:21am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/6 "2024-02-17T09:21:55Z")

</div>

> [@sijo](#):
>
> I guess you’re not simply looking for `a1 isa A && a2 isa A` ? 🙂

I think he is and I was going to write the same thing.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 17, 2024, 1:42pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/7 "2024-02-17T13:42:28Z")

</div>

No, he is not. He does not know what `A` is. He knows `a1` and `a2`.

> [@sijo](#):
>
> Another possibility in this case I think would be `nameof(typeof(a1)) == nameof(typeof(a2))`.

This does look promising. Thanks.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 18, 2024, 8:09am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/8 "2024-02-18T08:09:08Z")

</div>

> [@PetrKryslUCSD](#):
>
> No, he is not. He does not know what `A` is.

Well, this is new information. But I’m sorry if my phrasing came across as rude.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [February 18, 2024, 10:58am UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/9 "2024-02-18T10:58:13Z")

</div>

> [@PetrKryslUCSD](#):
>
> > [@sijo](#):
> >
> > Another possibility in this case I think would be `nameof(typeof(a1)) == nameof(typeof(a2))`.
> 
> This does look promising. Thanks.

`nameof` is going to be highly unreliable since it’s not namespaced at all.

```julia
julia> struct A{T}; a::T; end

julia> module Foo
       struct A{T}
           x::T
           y::T
           t::String
           w::Symbol
       end
       end;

julia> nameof(Foo.A{Int}) 
:A

julia> nameof(A{Int})
:A

julia> A{Int} == Foo.A{Int}
false

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [February 18, 2024, 4:21pm UTC](https://discourse.julialang.org/t/is-it-possible-to-get-an-incompletely-specified-type/110331/10 "2024-02-18T16:21:45Z")

</div>

Would there be a problem when using `nameof` together with `parentmodule`?

For example

```julia
julia> deparametrized(t) = getproperty(parentmodule(t), nameof(t));

julia> deparametrized(A{Int})
A

julia> deparametrized(Foo.A{Int})
Main.Foo.A

```
