# Function definitions with where T undefined

**URL:** <https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529>\
**Category:** New to Julia\
**Created:** [April 26, 2024, 10:34am UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529 "2024-04-26T10:34:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LucasMontoya4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmontoya4/32/205442_2.png) [@LucasMontoya4](https://discourse.julialang.org/u/LucasMontoya4)\
**Post date:** [April 26, 2024, 10:34am UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529/1 "2024-04-26T10:34:07Z")

</div>

Hi there, after looking at pieces of code around the internet, I have occasionally seen codes where functions are defined with `function foo(x, v::T) where T`, or something like that. I don’t understand the point of this `where T` at the end. If `T` is a type, then if you aren’t restricting it with a line like `where T<:Float64` or something like that, how does the `where T` at the end contribute in any way?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 26, 2024, 10:43am UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529/2 "2024-04-26T10:43:28Z")

</div>

Usually this is because you want to use `T` in the function body.

---

<div class="post-metadata">

**Author:** ![LucasMontoya4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmontoya4/32/205442_2.png) [@LucasMontoya4](https://discourse.julialang.org/u/LucasMontoya4)\
**Post date:** [April 26, 2024, 10:48am UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529/3 "2024-04-26T10:48:37Z")

</div>

Oh I see. So the function I wrote in the example would enable you to access the type T in the function. I just checked on a REPL to see that you indeed can NOT access the type T if you just write `function foo(x, v::T)`. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [April 26, 2024, 11:22am UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529/4 "2024-04-26T11:22:40Z")

</div>

Yes, the `where` clause of a function signature declares “parametric” types. Without it, the compiler goes to look for the literal type `T` and errors because it has not been defined.

Side note, this is used when you want access to T in the function body as @fredrikekre but it can also be used when you want two arguments of the same type, but you don’t care what types. Like:

```julia
same_type(::Any, ::Any) = false
same_type(::T, ::T) where T = true 

```

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [April 26, 2024, 12:27pm UTC](https://discourse.julialang.org/t/function-definitions-with-where-t-undefined/113529/5 "2024-04-26T12:27:00Z")

</div>

Yet another reason you might see this, where `T` may not even be used in the function body, is to [force specialization in some cases where Julia otherwise would not](https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing).
