# Type system limitations

**URL:** <https://discourse.julialang.org/t/type-system-limitations/34963>\
**Category:** General Usage\
**Tags:** question, parametric-types\
**Created:** [February 21, 2020, 9:53am UTC](https://discourse.julialang.org/t/type-system-limitations/34963 "2020-02-21T09:53:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [February 21, 2020, 9:53am UTC](https://discourse.julialang.org/t/type-system-limitations/34963/1 "2020-02-21T09:53:41Z")

</div>

Conceptually I want to do something like

```julia
function f(x::V{T}, y::W{U}) where V where T where W where U
    yy = convert(V{U}, y)
   ...
end

```

which is not possible, and seems to be a common problem ([https://discourse.julialang.org/t/how-to-get-the-container-type-of-a-container](https://discourse.julialang.org/t/how-to-get-the-container-type-of-a-container), [https://discourse.julialang.org/t/stripping-parameter-from-parametric-types/](https://discourse.julialang.org/t/stripping-parameter-from-parametric-types/), [https://discourse.julialang.org/t/extract-type-name-only-from-parametric-type/](https://discourse.julialang.org/t/extract-type-name-only-from-parametric-type/))

Maybe someone who knows the internals of the type system can explain if this is something that could be implemented in the future (and if there are plans to do so) or if this is something that is not possible due to general limitations of how the type system in Julia works.

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 21, 2020, 10:11am UTC](https://discourse.julialang.org/t/type-system-limitations/34963/2 "2020-02-21T10:11:48Z")

</div>

I think it’s probably super hacky so you most likely shouldn’t rely on it, but `basetype(V){U}` would work where you could steal the definition of `basetype` from [https://github.com/marius311/CMBLensing.jl/blob/1bfec09447b5ead5a77f404006af97a1d462729e/src/util.jl#L120](https://github.com/marius311/CMBLensing.jl/blob/1bfec09447b5ead5a77f404006af97a1d462729e/src/util.jl#L120)

---

<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:** [February 21, 2020, 10:38am UTC](https://discourse.julialang.org/t/type-system-limitations/34963/3 "2020-02-21T10:38:30Z")

</div>

The order of type parameters can be somewhat arbitrary and affected by other considerations (eg the most frequently used ones usually come first since that is a bit more convenient for parametric dispatch), so they should not be something to rely on.

In fact, they **may not even exist** :

```julia
struct HyperSpecializedVector <: AbstractVector{Float64} end
Base.size(::HyperSpecializedVector) = (7, )
Base.getindex(::HyperSpecializedVector, ::Int) = 0.444

```

is a subtype of `AbstractArray` that implements the interface, but has no type parameters.

So, in a nutshell, this kind of method dispatch is not very generic or useful as a design pattern.

You may want to give more context about your problem, so that an idiomatic solution can be suggested. I frequently find that generic APIs, possibly combined with traits, can provide an effective, convenient, and extensible solution.

---

<div class="post-metadata">

**Author:** ![gdkrmr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdkrmr/32/2791_2.png) [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Post date:** [February 21, 2020, 10:45am UTC](https://discourse.julialang.org/t/type-system-limitations/34963/4 "2020-02-21T10:45:18Z")

</div>

This was basically my first intuition to solve the issue [here](https://github.com/gdkrmr/WeightedOnlineStats.jl/issues/30#issuecomment-589158274) without having to add an extra dependency on `StaticArrays.jl`. I have solved it in a quite non-idiomatic way by checking the element type [here](https://github.com/gdkrmr/WeightedOnlineStats.jl/pull/36). The solution works fine but doesn’t feel very elegant.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [February 21, 2020, 11:12am UTC](https://discourse.julialang.org/t/type-system-limitations/34963/5 "2020-02-21T11:12:08Z")

</div>

Without building your own type, `BitArray{N} <: AbstractArray{Bool, N}`

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [February 21, 2020, 12:39pm UTC](https://discourse.julialang.org/t/type-system-limitations/34963/6 "2020-02-21T12:39:09Z")

</div>

Somewhat related: [Methods · The Julia Language](https://docs.julialang.org/en/v1/manual/methods/#Design-Patterns-with-Parametric-Methods-1), in particular `eltype`.
