3 ms·
This is really not different from how generics are implemented in many languages, it's almost identical to how haskell implements parametric functions w/ class
by almostdeadguy 8y ago
This is really not different from how generics are implemented in many languages, it's almost identical to how haskell implements parametric functions w/ class constraints (i.e. a dictionary w/ concrete functions for implementing the algorithm for a specific set of type parameters is passed): https://www.schoolofhaskell.com/user/jfischoff/instances-and-dictionaries https://www.schoolofhaskell.com/user/jfischoff/instances-and...
The only difference is that haskell generic functions can be specialized and the methods in the dictionary can be inlined: https://wiki.haskell.org/Inlining_and_Specialisation#What_is_specialisation.3F https://wiki.haskell.org/Inlining_and_Specialisation#What_is...