# Why Val{...}?

**URL:** <https://discourse.julialang.org/t/why-val/16035>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 8, 2018, 6:19pm UTC](https://discourse.julialang.org/t/why-val/16035 "2018-10-08T18:19:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 8, 2018, 7:15pm UTC](https://discourse.julialang.org/t/why-val/16035/7 "2018-10-08T19:15:10Z")

</div>

> [@e3c6](#):
>
> Is there an example, where constant propagation is not enough?

You might not only want to specialize on constants.

> [@Getproperty, decorations, inheritance in 0.7](https://discourse.julialang.org/t/getproperty-decorations-inheritance-in-0-7/11237/14):
>
> How about if I want to dynamically specialise on a certain value? using StaticArrays function f(n::Int) b = rand(SVector{n}) for i in 1:10000 b += rand(SVector{n}) end return b end function f(\_n::Val{n}) where n b = rand(SVector{n}) for i in 1:10000 b += rand(SVector{n}) end return b end g1() = f(rand(4:4)) g2() = f(Val(rand(4:4))) @time g1() @time g2() julia\> @time g1(); 0.015060 seconds (140.02 k allocations: 8.851 MiB) julia\> @time g2(…

---

_[View the full topic](https://discourse.julialang.org/t/why-val/16035)._
