3 ms·
OCaml modules and Haskell type classes are quite separate, too. I would make more sense to compare OCaml and Haskell modules. Haskell type classes implement ad-
by lindig 11y ago
OCaml modules and Haskell type classes are quite separate, too. I would make more sense to compare OCaml and Haskell modules. Haskell type classes implement ad-hoc polymorphism and OCaml doesn't have that at all. You can't implement in OCaml something like a show function that works on integers and strings and list of integers and so on like in Haskell using the Show type class.
- DonPellegrino 11y agoYou sort of can with functors or GADTs.
- lindig 11y agoLike you say, sort of. This would imply that you wrap all the basic types in a sum type. It's quite heavy. Using the PPX mechanism the compiler can also be extended to generate this code automatically but again, this isn't very natural at the moment.
- namanbharadwaj 11y agoIn fact, OCaml modules do correspond to Haskell type class instances, and there are ways to extend the ML module system to support ad-hoc style polymorphism (http://www.mpi-sws.org/~dreyer/papers/mtc/main-long.pdf http://www.mpi-sws.org/~dreyer/papers/mtc/main-long.pdf). On the other hand, you can also use modules as a simple namespacing mechanism (as in Haskell modules). But this does not capture the full power of the module system.