Reputation: 78
Is there a way in Julia to constrain the argument type of a function type? Let's say I have a function f = p::Int -> sqrt(p)
and I need to pass this function to other functions, is there a way to specify that these other functions take in functions which themselves take in Int
, something like my_func(f::Function{Int}) = ...
.
I am working on a raymarching implementation which uses functions to encode geometry. To combine two geometric objects, I need to take the minimum of their respective functions. Right now, I have this
Base.union(f1::Function, f2::Function) = p::Vec -> min(f1(p), f2(p))
But using @code_warntype, I see that sometimes it is type-stable while other times it isn't. I think that specifying the argument type of the argument function could help for this.
Related question: when using @code_warntype, what do the #num mean, for example in var"#226#227"{var"#223#224"{Torus}, var"#219#220"{Sphere}}
?
Upvotes: 1
Views: 184
Reputation: 2301
short answer: no, Julia does not have typed functions. But you can achieve type stability without this feature.
the #num
is just a name given to un-named variables.
Upvotes: 1