# Avoid re-compiling functions with specialized types

**URL:** <https://discourse.julialang.org/t/avoid-re-compiling-functions-with-specialized-types/69057>\
**Category:** New to Julia\
**Created:** [October 1, 2021, 4:45pm UTC](https://discourse.julialang.org/t/avoid-re-compiling-functions-with-specialized-types/69057 "2021-10-01T16:45:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 1, 2021, 5:25pm UTC](https://discourse.julialang.org/t/avoid-re-compiling-functions-with-specialized-types/69057/2 "2021-10-01T17:25:37Z")

</div>

> [@whatsthecraic](#):
>
> does invoking `foo(C{A}())` and `foo(C{B}())` still cause the compiler to generate two specialized functions, one for A and the other for B ?

yes. There is a `@nospecialize` macro to avoid specialization, but in general I do not think one wants to avoid that. There should be a very special reason for not wanting that specialization. (see [here](https://discourse.julialang.org/t/when-should-we-use-nospecialize/10392))

> [@whatsthecraic](#):
>
> If so, is there any difference in writing `foo(c::C)` and `foo(c::C{T)) where {T}` , besides the obvious case when T is referred in the body of foo for whatever reason?

no

---

_[View the full topic](https://discourse.julialang.org/t/avoid-re-compiling-functions-with-specialized-types/69057)._
