# Where T \<: Any

**URL:** <https://discourse.julialang.org/t/where-t-any/13592>\
**Category:** General Usage\
**Created:** [August 16, 2018, 11:20pm UTC](https://discourse.julialang.org/t/where-t-any/13592 "2018-08-16T23:20:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 16, 2018, 11:20pm UTC](https://discourse.julialang.org/t/where-t-any/13592/1 "2018-08-16T23:20:47Z")

</div>

I am trying to rewrite

```julia
julia> function permutations(v::Vector{T}) where T <: Any
                  nbase= length(v)
                  results= Vector{Vector{T}}(0)
                  for it=0:(nbase^nbase-1)
                      push!( results, v[digits( it; base=nbase, pad=nbase ) .+ 1] )
                  end#for
                  results
              end#function##

```

Under 0.7, I got the helpful warnings, that led me to write a function that no longer works under 1.0 (and that readers should now ignore, given the solution):

```julia
julia> function permutations(v::Vector{undef})
                   nbase= length(v)
                   results= Vector{typeof(v)}(0)
                   for it=0:(nbase^nbase-1)
                       push!( results, v[digits( it; base=nbase, pad=nbase ) .+ 1] )
                   end#for
                   results
               end#function##
permutations (generic function with 2 methods)

julia> permutations( ['a', 'b'] )
4-element Array{Array{Char,1},1}:
 ['a', 'a']
 ['b', 'a']
 ['a', 'b']
 ['b', 'b']

```

Alas, under 1.0, the function gives

```julia
julia> permutations( ['a', 'b'] )
ERROR: MethodError: no method matching permutations(::Array{Char,1})
Closest candidates are:
  permutations(::Array{array initializer with undefined values,1}) at REPL[1]:2
Stacktrace:
 [1] top-level scope at none:0

```

(PS: this is illustrative, but if this function already exists in julia, please let me know.)

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 16, 2018, 11:54pm UTC](https://discourse.julialang.org/t/where-t-any/13592/2 "2018-08-16T23:54:21Z")

</div>

What **is** the helpful warning you’ve got? Can you paste and follow that exactly? Your “fix” appears to be wrong. (It should be a warning about the constructor while you changed the type signature in a strange way).

I’m amused that it didn’t error but the reason your “fix” seems to work is that you didn’t actually removed the previous method, you are still calling the method with the depwarn which isn’t printing it anymore after the first call.

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [August 17, 2018, 12:29am UTC](https://discourse.julialang.org/t/where-t-any/13592/3 "2018-08-17T00:29:26Z")

</div>

Do note that femtocleaner will do all the deprecations in this example quite professionally.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 17, 2018, 12:49am UTC](https://discourse.julialang.org/t/where-t-any/13592/4 "2018-08-17T00:49:25Z")

</div>

the helpful warning in 0.7 was

```julia
julia> permutations( ['a', 'b'] )
┌ Warning: `Array{T, 1}(m::Int) where T` is deprecated, use `Array{T, 1}(undef, m)` instead.
│ caller = permutations(::Array{Char,1}) at REPL[94]:3
└ @ Main ./REPL[94]:3

```

which allowed me to guess the function that worked under 0.7. nice. alas, not under 1.0.

maybe I do need to discover femtocleaner… 🙂 well, actually, I am not using github, so this is not going to work for me.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 17, 2018, 12:57am UTC](https://discourse.julialang.org/t/where-t-any/13592/5 "2018-08-17T00:57:23Z")

</div>

I assume you realized that `Array{T, 1}` is `Vector{T}` so it’s asking you to change the call to the method `Vector{T}(m::Int) where T` to `Vector{T}(undef, m)` instead.

1. The first one is a method signature, the second is the call syntax, that’s why the `where T` is not there. It has nothng to do with removing `where T` from the code.
2. The `undef` is added in `()` not `{}`.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 17, 2018, 11:23pm UTC](https://discourse.julialang.org/t/where-t-any/13592/6 "2018-08-17T23:23:32Z")

</div>

hi yuyichao—going too fast. can you please write out the correct version for me? /iaw

---

<div class="post-metadata">

**Author:** ![Non-Contradiction](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-contradiction/32/2208_2.png) [@Non-Contradiction](https://discourse.julialang.org/u/Non-Contradiction)\
**Post date:** [August 17, 2018, 11:54pm UTC](https://discourse.julialang.org/t/where-t-any/13592/7 "2018-08-17T23:54:08Z")

</div>

I think what yuyichao and the error message means is that in your original function,  
`results= Vector{Vector{T}}(0)` should be `results = Vector{Vector{T}}(undef, 0)`.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [August 18, 2018, 12:14am UTC](https://discourse.julialang.org/t/where-t-any/13592/8 "2018-08-18T00:14:07Z")

</div>

oh, I see. I was staring at the code that worked fine under 0.7, and was thinking that was the one that needed a correction. Thank you.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [August 18, 2018, 12:27am UTC](https://discourse.julialang.org/t/where-t-any/13592/9 "2018-08-18T00:27:26Z")

</div>

> [@iwelch](#):
>
> the code that worked fine under 0.7,

No, as I said in the first post, it didn’t work. The whole thing works because you are not using it.
