# Can somebody explain this syntax?

**URL:** <https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519>\
**Category:** New to Julia\
**Tags:** type\
**Created:** [June 9, 2022, 6:40pm UTC](https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519 "2022-06-09T18:40:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharath\_Gururaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sharath_gururaj/32/19647_2.png) [@Sharath\_Gururaj](https://discourse.julialang.org/u/Sharath_Gururaj)\
**Post date:** [June 9, 2022, 6:40pm UTC](https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519/1 "2022-06-09T18:40:41Z")

</div>

We know that Typenames can be used as constructors  
for example

```julia
Float64(1.0)

```

I wanted to check how this is possible, so I ran

```julia
@which Float64(1.0)

```

It printed the following

```julia
(::Type{T})(x::T) where {T<:Number} = x

```

What is this mysterious syntax? The most mysterious part is the (::Type{T}).  
Where is the function name? I do know about the Type{T} objects,  
but I can’t get my head around the syntax. Plz help

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [June 9, 2022, 6:52pm UTC](https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519/2 "2022-06-09T18:52:06Z")

</div>

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

```julia
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
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.

---

<div class="post-metadata">

**Author:** ![Sharath\_Gururaj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sharath_gururaj/32/19647_2.png) [@Sharath\_Gururaj](https://discourse.julialang.org/u/Sharath_Gururaj)\
**Post date:** [June 9, 2022, 7:04pm UTC](https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519/3 "2022-06-09T19:04:45Z")

</div>

that’s amazing, thanks for the clear reply. Would be good to have this in the docs

---

<div class="post-metadata">

**Author:** ![dylanxyz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dylanxyz/32/36646_2.png) [@dylanxyz](https://discourse.julialang.org/u/dylanxyz)\
**Post date:** [June 9, 2022, 7:52pm UTC](https://discourse.julialang.org/t/can-somebody-explain-this-syntax/82519/4 "2022-06-09T19:52:27Z")

</div>

In the julia docs there is a section that talks about this

> Methods are associated with types, so it is possible to make any arbitrary Julia object “callable” by adding methods to its type. (Such “callable” objects are sometimes called “functors.”)

[Methods · The Julia Language](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects)
