'where T' vs 'where {T}'

Hi, I’m really liking Julia so far, but the documentation on the usage of where has me confused (despite finding a few posts here discussing it).

What would be the difference between:

same_type(x::T, y::T) where {T} = true
same_type(x::T, y::T) where T = true?


There is no difference. You need the {} when you have multiple types i.e:

same_type(x::S, y::T) where {S, T} = true

Without the {} you get a parsing error:

julia> same_type(x::S, y::T) where S, T = true
ERROR: UndefVarError: T not defined
 [1] top-level scope at none:1

So really where T is just a convenience to save some keystrokes if there is only 1 type.


Thanks pixel!

The curlies also make the single-clause version easier for my brain to parse. So it’s optional, but I find it useful for not accidentally misreading the where T = ... as having the function body defining what T is!