3 ms·
That Haskell code, as I understand it, will dynamically dispatch the call to max through the Ord typeclass dictionary passed at runtime. The C++ code will stat
by jemfinch 17y ago
That Haskell code, as I understand it, will dynamically dispatch the call to max through the Ord typeclass dictionary passed at runtime. The C++ code will statically choose the appropriate function.
- klipt 17y agoI'm pretty sure that Haskell typeclasses are also resolved at compile time. That's why you can't have a list containing different ordered types, for example (unless they can all be coerced to the same type).
- jemfinch 17y agoNo, you can't have a list containing different ordered types because the signature for comparison only permits two values of the same exact type, not any arbitrary member of class `Ord`. As I said before, Haskell passes [runtime dictionaries](http://www.haskell.org/haskellwiki/OOP_vs_type_classes http://www.haskell.org/haskellwiki/OOP_vs_type_classes). The compiler can perhaps infer many cases statically, but the core implementation is to pass around runtime dictionaries for typeclasses.