# How to qualify some numerical array type as argument

**URL:** https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969
**Category:** New to Julia
**Tags:** parametric-types
**Created:** [February 3, 2023, 4:08am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969 "2023-02-03T04:08:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)
#### Post date: [February 3, 2023, 4:08am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/1 "2023-02-03T04:08:41Z")

</div>

Hi, I’m implementing a function that initializes an array of certain type specified by a type parameter, which I considered using

```julia
ArrayInit(ARR::Type{A{V}},siz) where {A<:AbstractArray, V<:Number}

```

which does not work:

```julia
julia> Type{A{V}} where {A<:AbstractArray, V<:Number}
ERROR: TypeError: in Type{...} expression, expected UnionAll, got a value of type TypeVar

```

So what is the right way of passing something like `CuArray{Int}` as argument to `ArrayInit`? In other words, my question is how to **qualify** `ARR` as a numerical array type, i.e., `ARR<:AbstractArray{T} where T<:Number` is true, `ARR isa AbstractArray{T} where T` is false.

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 3, 2023, 4:09am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/2 "2023-02-03T04:09:40Z")

</div>

just uses `similar`

---

<div class="post-metadata">

### Author: ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)
#### Post date: [February 3, 2023, 4:32am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/3 "2023-02-03T04:32:52Z")

</div>

I seem to have found a qualifier as `::Type{AR} where AR<:AbstractArray{V} where V<:Number`:

```julia
julia> CuArray{Int} isa Type{AR} where AR<:AbstractArray{V} where V<:Number
true

julia> Array{Int} isa Type{AR} where AR<:AbstractArray{V} where V<:Number
true

julia> Tuple{Int} isa Type{AR} where AR<:AbstractArray{V} where V<:Number
false

julia> Array{String} isa Type{AR} where AR<:AbstractArray{V} where V<:Number
false

```

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [February 3, 2023, 4:38am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/4 "2023-02-03T04:38:49Z")

</div>

why do you need this ? you don’t have to annotate everything in Julia

---

<div class="post-metadata">

### Author: ![jinfreedom](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)
#### Post date: [February 3, 2023, 6:10am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/5 "2023-02-03T06:10:16Z")

</div>

To help throwing an error earlier than later into the code

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [February 3, 2023, 8:14am UTC](https://discourse.julialang.org/t/how-to-qualify-some-numerical-array-type-as-argument/93969/6 "2023-02-03T08:14:55Z")

</div>

You can use either of these:

```julia
ArrayInit(::Type{A}, siz) where {V<:Number, A<:AbstractArray{V}} = A(...)
ArrayInit(::Type{<:AbstractArray{<:Number}}, siz) = ...

```

The first is for when you need access to the variables `A` and `V`, the second is if you just need to restrict inputs.

You don’t have to write `ARR::Type{A}`, it is `A` which is your variable.
