# When using bits as type parameters they are regarded a subtype of Any

**URL:** <https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 3, 2021, 6:50am UTC](https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724 "2021-08-03T06:50:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [August 3, 2021, 6:50am UTC](https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724/1 "2021-08-03T06:50:11Z")

</div>

Hi all,  
using julia 1.6.1 there is currently an inconsistency when using bits (i.e. anything which is a bit-type) as type-parameters and when comparing bits directly with types.

```julia
julia> f(::Type{Tuple{T1}}) where T1 <: Any = :hi
f (generic function with 1 method)

julia> f(Tuple{1})
:hi

julia> 1 <: Any
ERROR: TypeError: in <:, expected Type, got a value of type Int64
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

```

The one or the other does not make sense, either `1 <: Any` or not. It should not make a difference whether it is a type-parameter or not.  
Or should it?

---

<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:** [August 3, 2021, 7:32am UTC](https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724/2 "2021-08-03T07:32:10Z")

</div>

I can see why this feels inconsistent. From the practical point of view, isbits in type parameter enables nice things such as `Matrix = Array{T, 2}`, and that a distinguished syntax is annoying to remember?

---

<div class="post-metadata">

**Author:** ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Post date:** [August 3, 2021, 8:26am UTC](https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724/3 "2021-08-03T08:26:39Z")

</div>

thanks for your remark. Yes, I also use this quite a lot and a recent package, in my case it simplifies the syntax nicely.

**Do you know whether there is an github issue which discussed this?**  
If it was done intentionally, I bet there was more discussion around it.

* * *

My current workaround is to just add another helper function to dispatch the parameter types normally, where everything works nicely again. So not a blocking point for so far luckily, but still it would be nice to address this inconsistency. At least with some documentaion added to the official julia docs.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 3, 2021, 9:33am UTC](https://discourse.julialang.org/t/when-using-bits-as-type-parameters-they-are-regarded-a-subtype-of-any/65724/4 "2021-08-03T09:33:05Z")

</div>

> [@schlichtanders](#):
>
> Or should it?

I would prefer to get an error, since using `<:` on something else than types is very likely to be a bug in my code. The earlier caught, the better.

You can always do something like

```julia
mysubtype(::Type{T}, ::Type{S}) where {T,S} = T <: S
mysubtype(_, ::Type{Any}) = true
mysubtype(_, _) = false

```

but such catch-all methods are generally not considered good style in Julia. Few functions should have methods for _everything_.
