Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在以下场景中,这是声明函数的更好方法
addnum(x::Float,y::Float) = x + y
对比
addnum(x::Float64,y::Float64) = x + y
Julia 手册风格指南敦促避免编写过于具体的类型。什么时候首选前者,什么时候首选后者?
除非您使用类型规范来覆盖函数的不同版本,否则最好简单地删除类型注释:
addnum(x, y) = x + y
因为这允许函数也适用于整数和复杂类型,然后编译器可以在编译时自动专门化函数。