# How does function named (::Type{T}) work in Julia?

**URL:** <https://discourse.julialang.org/t/how-does-function-named-type-t-work-in-julia/25175>\
**Category:** New to Julia\
**Created:** [June 12, 2019, 7:21am UTC](https://discourse.julialang.org/t/how-does-function-named-type-t-work-in-julia/25175 "2019-06-12T07:21:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HiroIshida](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hiroishida/32/7424_2.png) [@HiroIshida](https://discourse.julialang.org/u/HiroIshida)\
**Post date:** [June 12, 2019, 7:21am UTC](https://discourse.julialang.org/t/how-does-function-named-type-t-work-in-julia/25175/1 "2019-06-12T07:21:02Z")

</div>

I encountored syntax like `funcion (::Type{T})(...)...` and it seems that `(::Type{T})` is a function name. Is it correct? Also, if so, could you explain how it works or tell me the corresponding documentation?

I encountored this syntax [here](https://github.com/JuliaGeometry/GeometryTypes.jl/blob/master/src/meshes.jl). For example, the code below can be found at the lines 82-87.

> function (::Type{M})(  
> vertices::AbstractVector{Point{3, VT}}, faces::AbstractVector{FT}  
> ) where {M \<: HMesh, VT, FT \<: Face}  
> msh = PlainMesh{VT, FT}(vertices = vertices, faces = faces)  
> convert(M, msh)  
> end

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [June 12, 2019, 7:26am UTC](https://discourse.julialang.org/t/how-does-function-named-type-t-work-in-julia/25175/2 "2019-06-12T07:26:50Z")

</div>

See [https://docs.julialang.org/en/latest/manual/methods/#Function-like-objects-1](https://docs.julialang.org/en/latest/manual/methods/#Function-like-objects-1)

(and maybe [this](https://docs.julialang.org/en/latest/manual/types/#man-singleton-types-1) if you’re unfamiliar with `Type{T}`)

The snippet you posted basically defines constructors - it is defining a method for `DataType` objects which are a subtype of `M`. However, it doesn’t have to be a constructor in the sense of creating an object:

```julia
abstract type M end
struct A <: M end
struct B <: M end

function (::Type{T})(s::String) where {T <: M}
    println("I'm not constructing an object of type ", T, ". Instead I just print: ", s)
end

```

which gives

```julia
julia> A("test")
I'm not constructing an object of type A. Instead I just print: test

julia> B("hello world")
I'm not constructing an object of type B. Instead I just print: hello world

```
