# Could Julia have implicit type parameters?

**URL:** <https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914>\
**Category:** Internals & Design\
**Created:** [March 27, 2017, 10:16pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914 "2017-03-27T22:16:09Z")\
**Posts on this page:** 6\
**Page:** 1

<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:** [March 27, 2017, 10:16pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/1 "2017-03-27T22:16:09Z")

</div>

I’ve come to realize that (I think) I really want the following to be possible in Julia,

```julia
struct Wrapper{T<:SomeAbstractType{S}} <: OtherAbstractType{S}
    t::T
end

```

This doesn’t work because I have to explicitly declare the `S`, i.e. `Wrapper{S,T<:SomeAbstractType{S}}`. The sole reason I don’t want to do this explicitly is because in my actual code which has a few such parameters I’d like to make implicit, things get really really wordy and confusing to read when writing function definitions. If I _could_ define the above, then in theory I would always be able to capture as necessary, as if that `S` had been explicit, so it seems it could almost just be a cosmetic change:

```julia
foo(::Wrapper{<:SomeAbstractType}) = ...
foo(::Wrapper{<:SomeAbstractType{S}}) where {S} = ... # if I need the S

```

Is there any reason something like this doesn’t exist, or is there any interest for it? I feel like there’s a good chance something like this has been discussed but I couldn’t find anything.

---

<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:** [March 27, 2017, 10:20pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/2 "2017-03-27T22:20:17Z")

</div>

Ahh should have searched a bit more, I see now there’s a pretty recent discussion with links right here [Redundant type parameters](https://discourse.julialang.org/t/redundant-type-parameters/2251)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 27, 2017, 10:28pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/3 "2017-03-27T22:28:12Z")

</div>

> [@marius311](#):
>
> foo(::Wrapper{\<:SomeAbstractType}) = …

this exists on v0.6

> Implicit type parameters, e.g. Vector{\<:Real} is equivalent to Vector{T} where T\<:Real, and similarly for Vector{\>:Int} (#20414).

See this:

> <https://github.com/JuliaLang/julia/blob/master/NEWS.md>

---

<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:** [March 27, 2017, 10:30pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/4 "2017-03-27T22:30:00Z")

</div>

Both of those function definition exist in 0.6 already in fact, its the struct definition that does not.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 27, 2017, 10:40pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/5 "2017-03-27T22:40:51Z")

</div>

I see. Tagged as development.

My hunch is, it’s probably possible to take every type parameter which isn’t specified and place it in there as `S <: Any`. You’d have to come up with some convention for how the ordering would turn out though. But a good way to see if it would work well would be to try and make it happen with macros.

---

<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:** [March 27, 2017, 10:50pm UTC](https://discourse.julialang.org/t/could-julia-have-implicit-type-parameters/2914/6 "2017-03-27T22:50:32Z")

</div>

Yea, I’ve been toying with doing such a workaround by hand, basically

```julia
struct Wrapper{T<:SomeAbstractType, S} <: OtherAbstractType{S}
# enforce T <: SomeAbstractType{S} via inner constructor
end

```

and then (ab)use the fact that `Wrapper{T}` is an implicit UnionAll over S so you can omit writing the S. It works pretty well, but as mentioned by @jw3126 in the linked post there’s a problem with that `Wrapper{T}` is not a leaftype, so you can’t write e.g.,

```julia
foo(::Type{Wrapper{T}})

```

you have to either capture S expcitly in these cases, or do,

```julia
foo(::Type{<:Wrapper{T}})

```

which has been seeming to introduce lots of unnecessary ambiguities in my case.
