How to specify parametric type in function argument?

let’s say I have a parametric type like:

struct Param{T <: AbstractFloat}
    value::T
end

julia> p1 = Param(3.0)
Param{Float64}(3.0)

julia> p2 = Param(BigFloat(5.0) )
Param{BigFloat}(5.0)

how could I “tie” the type of argument b in the following function?

function fun(a::Param{T <: AbstractFloat},
            b::T)
    println(a.value + b)
end

ERROR: UndefVarError: T not defined

thanks.

function fun(a::Param{T}, b::T) where {T <: AbstractFloat}
    println(a.value + b)
end

See for example here.

5 Likes
function fun(a::Param{T},
            b::T) where {T<:AbstractFloat}
    println(a.value + b)
end
3 Likes