# AbstractArray doesn't capture the element type of a UnitRange

**URL:** https://discourse.julialang.org/t/abstractarray-doesnt-capture-the-element-type-of-a-unitrange/18159
**Category:** New to Julia
**Created:** [November 29, 2018, 7:07pm UTC](https://discourse.julialang.org/t/abstractarray-doesnt-capture-the-element-type-of-a-unitrange/18159 "2018-11-29T19:07:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hesham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hesham/32/21913_2.png) [@hesham](https://discourse.julialang.org/u/hesham)
#### Post date: [November 29, 2018, 7:07pm UTC](https://discourse.julialang.org/t/abstractarray-doesnt-capture-the-element-type-of-a-unitrange/18159/1 "2018-11-29T19:07:27Z")

</div>

Hi,

I have a function that I want to work on ranges and Vectors.

I see UnitRange{Int64} and Arrays{Int64,1} type hierarchy intersect at AbstractArray{Int64,1}, so I wrote my function as:

```julia
function test(t::AbstractArray{T,1}) where T
     return T
end

```

```julia
julia> test([1:3])
UnitRange{Int64}

julia> test([1,2,3])
Int64

```

I was expecting to see Int64 as a result for both.  
Any explanation?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [November 29, 2018, 7:19pm UTC](https://discourse.julialang.org/t/abstractarray-doesnt-capture-the-element-type-of-a-unitrange/18159/2 "2018-11-29T19:19:13Z")

</div>

In Julia, the `1:3` _itself_ is a UnitRange.

When you put brackets around it, it means you’re putting the UnitRange _into_ an array:

```julia
julia> A = [1:3]
1-element Array{UnitRange{Int64},1}:
 1:3

julia> [1:3,5:7]
2-element Array{UnitRange{Int64},1}:
 1:3
 5:7

```

Just do `test(1:3)` and you’ll find things to work as you expected.

Note that we print UnitRanges just like they’re entered, but they really are fully-functional array-like objects. You can see this by converting them to an `Array` or doing maths on them:

```julia
julia> r = 1:3
1:3

julia> size(r)
(3,)

julia> Array(r)
3-element Array{Int64,1}:
 1
 2
 3

julia> r .^ 2
3-element Array{Int64,1}:
 1
 4
 9

```

---

<div class="post-metadata">

### Author: ![hesham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hesham/32/21913_2.png) [@hesham](https://discourse.julialang.org/u/hesham)
#### Post date: [November 29, 2018, 7:59pm UTC](https://discourse.julialang.org/t/abstractarray-doesnt-capture-the-element-type-of-a-unitrange/18159/3 "2018-11-29T19:59:00Z")

</div>

This is indeed the issue. Thanks!
