Is it possible to implement Haskell typeclasses in C++? If yes, then how?
2 Answers
There's a few papers on this, which might be useful as background reading:
- C++ templates/traits versus Haskell type classes, Sunil Kothari , Martin Sulzmann
- A Comparative Study of Language Support for Generic Programming, Ronald Garcia , Jaakko Järvi , Andrew Lumsdaine , Jeremy Siek , Jeremiah Willcock
3 Comments
Matthieu M.
Am I the only one to notice that the OP's name is similar to the name of the first author of "C++ templates/traits versus Haskell type classes" ?
Matthieu M.
+1 for the second link, a categorization of the required features is very interesting indeed.
Matthieu M.
First paper: "C++ templates/traits versus Haskell type classes". There is an error at page 9 (Example 6), code is expressed in the body of a
struct. It seems to me that the author have only an approximative knowledge of C++ and this shows in the examples.The similar mechanism in C++ is called "concepts". The idea is to define a typeclass by defining the requirements of any type belonging to that class. C++ iterators make extensive use of concepts, and C++0x had intended to support direct syntax for them (rather than the indirect template tricks to perform concept checks C++ currently employs), but it appears this support has been dropped from the standard.