Return Val{c}(), which contains no run-time data. Types like this can be used to pass the information between functions through the value c, which must be an isbits value. The intent of this construct is to be able to dispatch on constants directly (at compile time) without having to test the value of the constant at run time.
function test(a::Vector{Int}, ::Val{2})
return 2 .* a
end
function test(a::Vector{Int}, ::Val{3})
return a.^3
end
a = [1, 2, 3]
println(test(a, Val(2)))
println(test(a, Val(3)))
julia> f(x)=if x==0 1 else 2 end
f (generic function with 1 method)
julia> g()=f(5)
g (generic function with 1 method)
julia> @code_llvm g()
; @ REPL[2]:1 within `g'
; Function Attrs: uwtable
define i64 @julia_g_16696() #0 {
top:
ret i64 2
}