# Correct way of: f(::T) where T = zero(T)?

**URL:** <https://discourse.julialang.org/t/correct-way-of-f-t-where-t-zero-t/67426>\
**Category:** General Usage\
**Created:** [August 31, 2021, 2:32pm UTC](https://discourse.julialang.org/t/correct-way-of-f-t-where-t-zero-t/67426 "2021-08-31T14:32:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [August 31, 2021, 2:32pm UTC](https://discourse.julialang.org/t/correct-way-of-f-t-where-t-zero-t/67426/1 "2021-08-31T14:32:43Z")

</div>

What is the correct way to pass only a type to control dispatch and use that type inside the function? As the title says, I want to do something like:

```julia
 f(::T) where T = zero(T)

```

Is this one?

```julia
julia> f(T::DataType) = zero(T)
f (generic function with 2 methods)

julia> f(Float64)
0.0

```

edit: that does not work because the type of `T` will be `DataType`, thus the function will not specialize for `T`.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [August 31, 2021, 2:36pm UTC](https://discourse.julialang.org/t/correct-way-of-f-t-where-t-zero-t/67426/2 "2021-08-31T14:36:13Z")

</div>

```julia
f(::Type{T}) where {T} = zero(T) 

```

---

<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:** [August 31, 2021, 5:14pm UTC](https://discourse.julialang.org/t/correct-way-of-f-t-where-t-zero-t/67426/3 "2021-08-31T17:14:31Z")

</div>

Similar question two weeks ago: [Dispatch on type only](https://discourse.julialang.org/t/dispatch-on-type-only/66498)
