New parametric functions syntax has a readability problem

@tim.holy Thanks

Re (3), here’s a quick made up example, requiring the function declaration to be wrapped in parenthesis:

julia> to_string(x::T) where T = string(x)
to_string (generic function with 1 method)

julia> to_string(x::T)::String where T = string(x)
ERROR: UndefVarError: T not defined

julia> (to_string(x::T)::String) where T = string(x)
to_string (generic function with 1 method)

(I’ve updated my (3) comment to reflect that wrapping in (...) is actually a requirement now. I was having in mind older discussions like Best practice for parametric return type declarations in v0.7 (and v1.0) and Proper way to declare return types parametrically in short-form functions in Julia 0.6).

Yes, I agree that the first convert example was very complicated and the new syntax made it much better. But even in the above examples, I can’t see why the parametric expression could not be provided as part of the argument list.


Foo(a::A%, b::B%)


Foo(a::A% <: AbstractType, b::B% <: OtherAbstractType)

where % stands for the where part.

1 Like