# How to specify that a function which has several (but a limited amount) of possible types as inputs and outputs?

**URL:** <https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041>\
**Category:** Performance\
**Created:** [December 9, 2019, 10:02am UTC](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041 "2019-12-09T10:02:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gobs](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@gobs](https://discourse.julialang.org/u/gobs)\
**Post date:** [December 9, 2019, 10:02am UTC](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041/1 "2019-12-09T10:02:51Z")

</div>

My code for formulating a specific JuMP optimisation model has started getting quite slow, and I would like to start optimising it by specifying types.

One of the main functions I call just searches through two dictionaries (which have either strings or symbols as keys) to return either 1) a Float64 2) an Int16 3) an array of either of those or 4) a string.

Is there a way of telling Julia that these are the only possible options, so that it can compile this function?

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [December 9, 2019, 10:21am UTC](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041/2 "2019-12-09T10:21:37Z")

</div>

Restricting the input types doesn’t change performance. See [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/)

---

<div class="post-metadata">

**Author:** ![gobs](https://avatars.discourse-cdn.com/v4/letter/g/bc8723/32.png) [@gobs](https://discourse.julialang.org/u/gobs)\
**Post date:** [December 9, 2019, 11:02am UTC](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041/3 "2019-12-09T11:02:04Z")

</div>

There must be something else slowing down my code then…
