小编Dim*_*ris的帖子

如何缩短函数体中的类型

最好用一个例子来解释:

我定义了一个类型

type myType
    ?::Float64
    ?::Float64
end
z = myType( 1., 2. )
Run Code Online (Sandbox Code Playgroud)

然后假设我想将此类型作为参数传递给函数:

myFunc( x::Vector{Float64}, m::myType ) =
    x[1].^m.?+x[2].^m.?
Run Code Online (Sandbox Code Playgroud)

有没有办法传递,myType以便我可以以"更清洁"的方式在函数体中实际使用它,如下所示:

    x[1].^?+x[2].^?
Run Code Online (Sandbox Code Playgroud)

谢谢你的回答.

julia

2
推荐指数
1
解决办法
115
查看次数

标签 统计

julia ×1