@mratsim Thank you for your detailed and informative response, also I didn't 
know about the do statement in Nim that's something else new for me. My main 
takeaway is that I don't always have to use runtime resolution, especially 
because the kind of code I write is mostly statistics/machine learning - type 
algorithms where performance is important and virtual method calls (dynamic 
dispatch) has an adverse impact.

To be clear the example you gave using AbstractKernel[T] is resolved at compile 
time rather than at run time, AbstractKernel[T] is essentially a function 
pointer whose type (along with the matrix) is known at compile time. I guess 
OOP-based polymorphism is one way to provide a common interface to function 
dispatch and parametric polymorphism is another - which has no performance 
penalties but can not be used in instances where type resolution at compile 
time is not available, but in instances where this is not the case it pays to 
use parametric polymorphism.

Reply via email to