Best practice for parametric return type declarations in v0.7 (and v1.0)

Hi all,

I just encountered this and this, which indicate that for v0.7 (and therefore v1.0), the best syntax for one-liner functions that include a parametric return type declaration is to write the function inside parentheses, e.g.

(f1(x::Vector{T})::Vector{T}) where {T} = x

since f1(x::Vector{T})::Vector{T} where {T} = x will result in a UndefVarError: T not defined. However, I also noticed that the syntax:

f1(x::Vector{T} where {T})::Vector{T} = x

appears to work.

Is one of these two options preferred over the other? Do they actually do exactly the same thing or are there some subtle differences? Most importantly, if I’m updating my code with an eye on v1.0, should I prefer one over the other, i.e. is one of these forms likely to be eliminated eventually?

Cheers,

Colin

1 Like

It doesn’t though:

julia> f1(x::Vector{T} where {T})::Vector{T} = x
f1 (generic function with 1 method)

julia> f1(rand(2))
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] f1(::Array{Float64,1}) at ./REPL[1]:1

Yep that’s a fairly compelling point… I only tested whether it compiled and forgot to check that it would also run. Apologies. -colin