# How do i create a custom supertype?

**URL:** https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166
**Category:** New to Julia
**Tags:** question, type
**Created:** [July 18, 2024, 1:39am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166 "2024-07-18T01:39:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Rockdeldiablo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rockdeldiablo/32/19833_2.png) [@Rockdeldiablo](https://discourse.julialang.org/u/Rockdeldiablo)
#### Post date: [July 18, 2024, 1:39am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166/1 "2024-07-18T01:39:33Z")

</div>

hi everyone. i have a function that can return as output results of type Matrix{Categorical{Floaxx, Vector{Floatxx}}}  
where xx stands for the usual 16,32 or 64.

i was trying to create a test for such function that check that the output has this generic kind of type but i don’t know how to do it. if i evaluate results\<: AbstractArray it works but it’s too generic for what i want to do

---

<div class="post-metadata">

### Author: ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)
#### Post date: [July 18, 2024, 1:47am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166/2 "2024-07-18T01:47:45Z")

</div>

```julia-repl
julia> struct Categorical{S, T} end

julia> upper_bound = Matrix{Categorical{T, Vector{T}}} where {T <: AbstractFloat}
Array{Categorical{T, Vector{T}}, 2} where T<:AbstractFloat

julia> Matrix{Categorical{Float64, Vector{Float64}}} <: upper_bound
true

```

(In the first line I defined a parametric struct named `Categorical` just so the code would run. Yours should behave the same with the `Categorical` type that you are getting from somewhere.)

---

<div class="post-metadata">

### Author: ![Rockdeldiablo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rockdeldiablo/32/19833_2.png) [@Rockdeldiablo](https://discourse.julialang.org/u/Rockdeldiablo)
#### Post date: [July 18, 2024, 2:21am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166/3 "2024-07-18T02:21:13Z")

</div>

> [@CameronBieganek](#):
>
> ```julia
> upper_bound = Matrix{Categorical{T, Vector{T}}} where {T <: AbstractFloat}
> Array{Categorical{T, Vector{T}}, 2} where T<:AbstractFloat
> 
> ```

thanks. it was from Distributions.jl, i should have added this information.  
when i try to test the function i get the error

> Expression: typeof(predict(la, X; predict\_proba = true, ret\_distr = true)) == upper\_bound  
> Evaluated: Matrix{Categorical{Float32, Vector{Float32}}} == Array{Distributions.DiscreteNonParametric{Int64, T, Base.OneTo{Int64}, Vector{T}}, 2} where T\<:AbstractFloat

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [July 18, 2024, 2:53am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166/4 "2024-07-18T02:53:36Z")

</div>

> [@Rockdeldiablo](#):
>
> ==

I think you mean `<:` instead. BTW, please use Markdown code blocks in the future to make your posts readable.

---

<div class="post-metadata">

### Author: ![Rockdeldiablo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rockdeldiablo/32/19833_2.png) [@Rockdeldiablo](https://discourse.julialang.org/u/Rockdeldiablo)
#### Post date: [July 18, 2024, 3:00am UTC](https://discourse.julialang.org/t/how-do-i-create-a-custom-supertype/117166/5 "2024-07-18T03:00:20Z")

</div>

ahhh true, i missed it when i copy pasted hahahha thanks to both.  
i will use markdown in the future.
