How to declare parametric with return type of a function?

It’s just a slightly annoying parsing issue. Your definition is getting parsed as f(a::T)::(Bool where {T <: Number}), which isn’t what you want. You can do:

julia> (f(a::T)::Bool) where {T <: Number} = a == 1
f (generic function with 1 method)

julia> f(1.0)
true

And by the way, you can see for yourself how the expression is parsed by quoting it, in case you’re ever curious:

julia> :(f(a::T)::Bool where {T <: Number} = a == 1)
:(f(a::T)::(Bool where T <: Number) = begin
          #= REPL[3]:1 =#
          a == 1
      end)

note how the (Bool where T <: Number) is grouped together.

5 Likes