Now, I want to dynamically add methods based on arguments that are not known ahead of time. For example, I might be given an array of types [T1, T2, T3] and another function h and I want to add a method
fw.f(::T1,::T2,::T3) = h
Any ideas how I can do this (preferably without using @eval)?
So do you want a fallback that returns the function object h for any set of argument types for which you havenât created a more specific method? If thatâs the case,
fw.f(args...) = h
would work. But maybe you could explain a little bit more about what youâre trying to accomplish (wasnât straightforward to gather from the issue you linked); it could be that I donât understand the problem, or that thereâs a different approach that is more appropriate.
As a side note, having f as an abstractly typed field in fwrap (Function is an abstract type) means that all dispatch will happen at runtime, which is bad for performance.
Iâm pretty sure that in general youâll need eval; the only way I know to add methods is by âcodingâ them.
Without having read the linked issue, maybe this could help:
If performance is not paramount (you should profile) or if JIT-time is an issue, then you could hand-code the dispatch: