Can somebody explain this syntax?

The syntax (::X)(...) is for making objects of type X callable. Here’s an example. By default strings are not callable:

julia> "a"("b")
ERROR: MethodError: objects of type String are not callable
Stacktrace:
 [1] top-level scope
   @ REPL[1]:1

Now we use the syntax from above and make all strings callable, executing a concatenation function (this is of course a silly example and there’s no reason why you’d do this)

julia> (s::String)(x) = s * x

julia> "a"("b")
"ab"

So the syntax you asked about is a generic definition which just says that calling any Number subtype with a number of that type returns the number. So Float64(1.0) = 1.0. I don’t know why that needs to exist specifically, but that’s what the code does.

10 Likes