# What are lower bounds for types?

**URL:** https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712
**Category:** New to Julia
**Tags:** type, parametric-types
**Created:** [September 16, 2020, 3:05pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712 "2020-09-16T15:05:15Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![astadmistry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astadmistry/32/17299_2.png) [@astadmistry](https://discourse.julialang.org/u/astadmistry)
#### Post date: [September 16, 2020, 3:05pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/1 "2020-09-16T15:05:15Z")

</div>

I’m trying to understand what lower bounds are for types. I ran the following code which shows which subtypes (recursively) of number satisfies/rejects `Int <: T <: Real` in hope of gaining an understanding, however I’m still lost. 😪

```python
Number
├─ Complex
└─ Real
   ├─ AbstractFloat
   │ ├─ BigFloat
   │ ├─ Float16
   │ ├─ Float32
   │ └─ Float64
   ├─ AbstractIrrational
   │ └─ Irrational
   ├─ FixedPoint
   │ ├─ Fixed
   │ └─ Normed
   ├─ Integer
   │ ├─ Bool
   │ ├─ Signed
   │ │ ├─ BigInt
   │ │ ├─ Int128
   │ │ ├─ Int16
   │ │ ├─ Int32
   │ │ ├─ Int64
   │ │ └─ Int8
   │ └─ Unsigned
   │ ├─ UInt128
   │ ├─ UInt16
   │ ├─ UInt32
   │ ├─ UInt64
   │ └─ UInt8
   ├─ Rational
   └─ TestStat

```

```julia
function stype(input)
    arr = []
    append!(arr,subtypes(input))
    for x in arr
        z = subtypes(x)
        if (z != Type[])
            append!(arr,z)
        end
    end
    arr
end

for T in stype(Number)
    @show T, Int <: T <: Real
end

```

```julia
(T, Int <: T <: Real) = (Complex, false)
(T, Int <: T <: Real) = (Real, true)
(T, Int <: T <: Real) = (AbstractFloat, false)
(T, Int <: T <: Real) = (AbstractIrrational, false)
(T, Int <: T <: Real) = (FixedPointNumbers.FixedPoint, false)
(T, Int <: T <: Real) = (Integer, true)
(T, Int <: T <: Real) = (Rational, false)
(T, Int <: T <: Real) = (StatsBase.TestStat, false)
(T, Int <: T <: Real) = (BigFloat, false)
(T, Int <: T <: Real) = (Float16, false)
(T, Int <: T <: Real) = (Float32, false)
(T, Int <: T <: Real) = (Float64, false)
(T, Int <: T <: Real) = (Irrational, false)
(T, Int <: T <: Real) = (FixedPointNumbers.Fixed, false)
(T, Int <: T <: Real) = (FixedPointNumbers.Normed, false)
(T, Int <: T <: Real) = (Bool, false)
(T, Int <: T <: Real) = (Signed, true)
(T, Int <: T <: Real) = (Unsigned, false)
(T, Int <: T <: Real) = (BigInt, false)
(T, Int <: T <: Real) = (Int128, false)
(T, Int <: T <: Real) = (Int16, false)
(T, Int <: T <: Real) = (Int32, false)
(T, Int <: T <: Real) = (Int64, true)
(T, Int <: T <: Real) = (Int8, false)
(T, Int <: T <: Real) = (UInt128, false)
(T, Int <: T <: Real) = (UInt16, false)
(T, Int <: T <: Real) = (UInt32, false)
(T, Int <: T <: Real) = (UInt64, false)
(T, Int <: T <: Real) = (UInt8, false)

```

I don’t understand why `Int <: T <: Real` is only true for Real, Integer, Signed and Int64

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [September 16, 2020, 3:23pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/2 "2020-09-16T15:23:18Z")

</div>

`Int` is just an alias for `Int64` on 64-bit platforms and `Int32` on 32-bit platforms. Since you seem to be running a 64-bit Julia version, you get exactly the same results for `Int` as you get for `Int64`. Does that answer your question?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 16, 2020, 3:26pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/3 "2020-09-16T15:26:59Z")

</div>

Note `Integer`is probably what you meant.

---

<div class="post-metadata">

### Author: ![astadmistry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astadmistry/32/17299_2.png) [@astadmistry](https://discourse.julialang.org/u/astadmistry)
#### Post date: [September 16, 2020, 3:30pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/4 "2020-09-16T15:30:36Z")

</div>

Yes, `Integer` is what I meant, however I still don’t understand what the lower bound means.

```julia
Integer <: Int64 <: Real

```

```julia
false

```

Why is this false? What does the lower bound mean?

---

<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: [September 16, 2020, 3:36pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/5 "2020-09-16T15:36:26Z")

</div>

`Int64` (which is a concrete type) is a subtype of `Integer` (which is an abstract type). The reverse cannot be true.

---

<div class="post-metadata">

### Author: ![astadmistry](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/astadmistry/32/17299_2.png) [@astadmistry](https://discourse.julialang.org/u/astadmistry)
#### Post date: [September 16, 2020, 3:40pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/6 "2020-09-16T15:40:21Z")

</div>

This makes sense, thank you for the explanation, however when would you use an upper bound with a lower bound?

---

<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: [September 16, 2020, 3:43pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/7 "2020-09-16T15:43:56Z")

</div>

I never use them. I’ve seen them used, but cannot remember what for.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [September 16, 2020, 3:50pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/8 "2020-09-16T15:50:49Z")

</div>

One example would be `Missing<:T<: Integer` which is a way of writing `T<: Union{Missing, Integer}`. In general, lower bounds aren’t widely used.

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [September 16, 2020, 4:01pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/9 "2020-09-16T16:01:15Z")

</div>

I don’t think that’s true:

```julia
julia> Missing <: Missing <: Integer
false

julia> Missing <: Int <: Integer
false

```

---

<div class="post-metadata">

### Author: ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)
#### Post date: [September 16, 2020, 4:03pm UTC](https://discourse.julialang.org/t/what-are-lower-bounds-for-types/46712/10 "2020-09-16T16:03:43Z")

</div>

Lower bounds are sometimes useful though, for example if you want to check whether a vector can store missing values:

```julia
julia> [1, missing, 3] isa Vector{>:Missing}
true

julia> [1, 2, 3] isa Vector{>:Missing}
false

```
